Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'zennit' has no attribute '...' #29

Open
lowlorenz opened this issue Aug 6, 2024 · 2 comments
Open

AttributeError: module 'zennit' has no attribute '...' #29

lowlorenz opened this issue Aug 6, 2024 · 2 comments

Comments

@lowlorenz
Copy link
Contributor

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

  1. Update CRP Requirements: Consider updating CRP to require zennit>=0.4.7 to ensure compatibility with the latest Zennit practices and documentation.
  2. 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

@lowlorenz
Copy link
Contributor Author

Related to #14

@rachtibat
Copy link
Owner

Hey, thank you for the issue!
I am still not sure how the new zennit version handles our custom backward hooks at

class MaskHook:

Maybe we could update zennit to the newest version, fix the import problem you mentioned, and run the tests in https://github.com/rachtibat/zennit-crp/tree/master/tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants