serre-lab / Harmonization

👋 Aligning Human & Machine Vision using explainability
https://serre-lab.github.io/Harmonization/
MIT License
43 stars 10 forks source link

ModuleNotFoundError: No module named 'keras_cv_attention_models.maxvit' #12

Open LukasMut opened 1 year ago

LukasMut commented 1 year ago

I am currently trying to add your models to the thingsvision toolbox, but we keep getting the following error message:

  File "/Users/runner/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/harmonization/models/maxvit.py", line 6, in <module>
    from keras_cv_attention_models.maxvit import  MaxViT_Tiny
ModuleNotFoundError: No module named 'keras_cv_attention_models.maxvit'

From this commit I can infer that you've added MaxViT only recently. Did you actually test whether the imports work as expected? From what I can see here is that you need to use keras-cv-attention-models rather than keras_cv_attention_models when installing the module via pip. However, I am not 100% sure whether that's the issue. You can find the PR that is trying to add your models to the thingsvision toolbox here.

fel-thomas commented 1 year ago

Hello Lukas, thank you for your PR. In fact, I am really admirative of the works in ThingsVision and I would be interested in assisting you with your project!

Concerning the error, I am currently utilizing the (remarkable) work of @leondgarse:

pip install -U keras-cv-attention-models
# Or
pip install -U git+https://github.com/leondgarse/keras_cv_attention_models

and a line of the README file specifies what could potentially be the cause of the issue: "Currently recommended TF version is tensorflow==2.10.0. Especially for training or TFLite conversion."

As for myself, I have not encountered any problems, as demonstrated by the following output:

>>> import keras_cv_attention_models
>>> from keras_cv_attention_models import maxvit
>>> maxvit
<module 'keras_cv_attention_models.maxvit' from '/Users/thomas/miniforge3/lib/python3.9/site-packages/keras_cv_attention_models/maxvit/__init__.py'>
>>> keras_cv_attention_models.__version__
'1.3.9'

I am wondering if the version of TensorFlow or Python that you are using (perhaps on Codecov?) is the issue. What do you think? Please feel free to contact me by email at thomas_fel@brown.edu.

leondgarse commented 1 year ago

Ya, the package name for pip install is keras-cv-attention-models. I think you should use this name in your requirements.txt, not keras_cv_attention_models.

LukasMut commented 1 year ago

Ya, the package name for pip install is keras-cv-attention-models. I think you should use this name in your requirements.txt, not keras_cv_attention_models.

Yeh, that was my hunch.

LukasMut commented 1 year ago

Hello Lukas,

thank you for your PR. In fact, I am really admirative of the works in ThingsVision and I would be interested in assisting you with your project!

Concerning the error, I am currently utilizing the (remarkable) work of @leondgarse:


pip install -U keras-cv-attention-models

# Or

pip install -U git+https://github.com/leondgarse/keras_cv_attention_models

and a line of the README file specifies what could potentially be the cause of the issue:

"Currently recommended TF version is tensorflow==2.10.0. Especially for training or TFLite conversion."

As for myself, I have not encountered any problems, as demonstrated by the following output:


>>> import keras_cv_attention_models

>>> from keras_cv_attention_models import maxvit

>>> maxvit

<module 'keras_cv_attention_models.maxvit' from '/Users/thomas/miniforge3/lib/python3.9/site-packages/keras_cv_attention_models/maxvit/__init__.py'>

>>> keras_cv_attention_models.__version__

'1.3.9'

I am wondering if the version of TensorFlow or Python that you are using (perhaps on Codecov?) is the issue. What do you think? Please feel free to contact me by email at thomas_fel@brown.edu.

Thanks for your response Thomas! If you're interested, I can add you to the thingsvision team. I am always happy to welcome people who are interested to help expand the project. Will shoot you an email. :)

Regarding the error message: I don't think that it has something to do with the TensorFlow version. That wouldn't make any sense. Otherwise @leondgarse would not have phrased it as a recommendation -- "especially for training" -- rather than a necessity.

It appears that the package is not installed correctly which should not depend on the TensorFlow version, at least not for versions that aren't very different from the recommended version. If that's really the case though, then this has to be explicitly stated in the description of the keras_cv_attention_models package.

We can try to change the TensorFlow version and run the tests again on our end, but my hunch is that it won't fix the problem.

LukasMut commented 1 year ago

A quick heads up: changing the TensorFlow version on our end does not resolve the error.

fel-thomas commented 1 year ago

Thanks everyone, should be updated on pipy ! :)

LukasMut commented 1 year ago

Unfortunately, this does not fix the error. I still get the following error message

  File "/Users/runner/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/harmonization/__init__.py", line 13, in <module>
    from . import models
  File "/Users/runner/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/harmonization/models/__init__.py", line 11, in <module>
    from .maxvit import load_tiny_MaxViT
  File "/Users/runner/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/harmonization/models/maxvit.py", line 6, in <module>
    from keras_cv_attention_models.maxvit import  MaxViT_Tiny
ModuleNotFoundError: No module named 'keras_cv_attention_models.maxvit'
LukasMut commented 1 year ago

Ok, I could finally figure out what the problem is. The problem is caused by the keras-cv-attention-models package. When I try to import MaxViT_Tiny like so

from keras_cv_attention_models.maxvit import MaxViT_Tiny

then I get the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'keras_cv_attention_models.maxvit'

When I try to import the maxvit module differently

from keras_cv_attention_models import maxvit

I get the following message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'maxvit' from 'keras_cv_attention_models' (/Users/lmuttenthaler/anaconda3/envs/thingsvision/lib/python3.9/site-packages/keras_cv_attention_models/__init__.py)

However, when I try to import LeViT128 instead of MaxViT_Tiny

from keras_cv_attention_models.levit import LeViT128

then everything works just fine and I see no error message. So, it seems as if something goes wrong with maxvit. I am copying @leondgarse to fix this. MaxViT_Tiny cannot work for you either @fel-thomas. So, I'd recommend taking it out from Harmonization until this is fixed, otherwise we cannot use the Harmonization package because it will always through that error.

leondgarse commented 1 year ago

As we discussed here #112, should specify keras-cv-attention-models>=1.3.5 in your requirements.txt for using MaxViT. What's your opinion?

LukasMut commented 1 year ago

As we discussed here #112, should specify keras-cv-attention-models>=1.3.5 in your requirements.txt for using MaxViT. What's your opinion?

I've just submitted a PR that does that.

LukasMut commented 1 year ago

@leondgarse, should we specify the tensorflow version as well or keep it unspecified?

leondgarse commented 1 year ago

I didn't specify TF version in my package, as there even someone using it in TF 1 earlier. If need to made sure most things works, may specify tensorflow>=2.5.0.

LukasMut commented 1 year ago

I get the following error for any keras-cv-attention-models version above version 1.2.5 on macos:

ERROR: Could not find a version that satisfies the requirement tensorflow-macos; platform_system == "Darwin" (from keras-cv-attention-models) (from versions: none)
ERROR: No matching distribution found for tensorflow-macos; platform_system == "Darwin"

It works fine though for any version below 1.2.5, but below 1.2.5 there does not exist MaxViT. So, we have a problem here. See #112.