zennit-crp
zennit-crp copied to clipboard
AttributeError: module 'zennit' has no attribute '...'
Issue: Common Import Problem with CRP and Zennit 0.4.6
Background
The CRP package currently enforces the use of zennit==0.4.6
, while the latest version of zennit is 0.5.1. Users following the latest Zennit documentation may encounter import errors due to changes in how packages are loaded.
Problem
In the update from Zennit 0.4.6 to 0.4.7, there was a commit that modified the __init__.py
file to import all modules of the Zennit package into the Zennit namespace. This change allows for importing modules like ResNetCanonizer
directly:
import zennit
canonizer = zennit.torchvision.ResNetCanonizer()
However, in version 0.4.6, which CRP currently enforces, this import leads to the following error:
import zennit
canonizer = zennit.torchvision.ResNetCanonizer()
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> AttributeError: module 'zennit' has no attribute 'torchvision'
This error occurs because the torchvision
module is not loaded in Zennit's __init__.py
in version 0.4.6.
Solution
To prevent this error, explicitly import the zennit.torchvision
module as follows:
import zennit.torchvision
canonizer = zennit.torchvision.ResNetCanonizer()
For more information on Python namespaces and module imports, refer to the Python tutorial on namespaces.
Suggestions for Resolution
-
Update CRP Requirements: Consider updating CRP to require
zennit>=0.4.7
to ensure compatibility with the latest Zennit practices and documentation. - Documentation Update: Add a note in the CRP documentation to inform users about this import issue and the temporary workaround until the package requirements are updated.
@rachtibat