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

cannot import name 'torchvision_ssl_encoder' #210

Closed
hrnademi opened this issue Sep 11, 2020 · 5 comments · Fixed by #350
Closed

cannot import name 'torchvision_ssl_encoder' #210

hrnademi opened this issue Sep 11, 2020 · 5 comments · Fixed by #350
Labels
bug Something isn't working help wanted Extra attention is needed Priority High priority task
Milestone

Comments

@hrnademi
Copy link

Hi
I just want to run following example, but I get this error "cannot import name 'torchvision_ssl_encoder'"

from pl_bolts.utils.self_supervised import torchvision_ssl_encoder

resnet = torchvision_ssl_encoder('resnet18', pretrained=False, return_all_feature_maps=True)
x = torch.rand(3, 3, 32, 32)

feat_maps = resnet(x)

Is something wrong with pytorch-lightning-bolts?

@github-actions
Copy link

Hi! thanks for your contribution!, great first issue!

@Borda Borda added the question Further information is requested label Oct 15, 2020
@Borda
Copy link
Member

Borda commented Oct 15, 2020

@hrnademi can you share the exact message and some more details about your local env?

@ananyahjha93
Copy link
Contributor

ananyahjha93 commented Nov 2, 2020

@hrnademi
I think torchvision_ssl_encoder is an internal function and thus hasn't been exported in utils/init.py. You can use the docs here: https://pytorch-lightning-bolts.readthedocs.io/en/latest/self_supervised_models.html to import the available pre-trained self-supervised learning models present.

which pre-trained encoder are you looking at specifically?

@Borda
Copy link
Member

Borda commented Nov 9, 2020

I can confirm this issue on master

>>> from pl_bolts.utils.self_supervised import torchvision_ssl_encoder
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jirka/Workspace/pytorch-lightning-bolts/pl_bolts/utils/self_supervised.py", line 1, in <module>
    from pl_bolts.models.self_supervised import resnets
  File "/Users/jirka/Workspace/pytorch-lightning-bolts/pl_bolts/models/self_supervised/__init__.py", line 21, in <module>
    from pl_bolts.models.self_supervised.amdim.amdim_module import AMDIM
  File "/Users/jirka/Workspace/pytorch-lightning-bolts/pl_bolts/models/self_supervised/amdim/__init__.py", line 1, in <module>
    from pl_bolts.models.self_supervised.amdim.amdim_module import AMDIM
  File "/Users/jirka/Workspace/pytorch-lightning-bolts/pl_bolts/models/self_supervised/amdim/amdim_module.py", line 16, in <module>
    from pl_bolts.utils.self_supervised import torchvision_ssl_encoder
ImportError: cannot import name 'torchvision_ssl_encoder' from 'pl_bolts.utils.self_supervised' (/Users/jirka/Workspace/pytorch-lightning-bolts/pl_bolts/utils/self_supervised.py)

seems like we have cyclic import somewhere...

@Borda Borda added fix fixing issues... help wanted Extra attention is needed Priority High priority task and removed question Further information is requested labels Nov 9, 2020
@Borda Borda closed this as completed in #350 Nov 9, 2020
@Borda Borda added this to the v0.3 milestone Jan 18, 2021
@MaveriQ
Copy link

MaveriQ commented Nov 3, 2021

I have bolts version '0.3.4' and I am still getting the error. This is the error trace from a jupyter notebook.

In [1]: from pl_bolts.utils.self_supervised import torchvision_ssl_encoder
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5668ca49f041> in <module>
----> 1 from pl_bolts.utils.self_supervised import torchvision_ssl_encoder

/mounts/work/jabbar/bin/anaconda3/envs/barlowbert/lib/python3.8/site-packages/pl_bolts/utils/self_supervised.py in <module>
      1 from torch.nn import Module
      2 
----> 3 from pl_bolts.models.self_supervised import resnets
      4 from pl_bolts.utils.semi_supervised import Identity
      5 

/mounts/work/jabbar/bin/anaconda3/envs/barlowbert/lib/python3.8/site-packages/pl_bolts/models/self_supervised/__init__.py in <module>
     19 
     20 """
---> 21 from pl_bolts.models.self_supervised.amdim.amdim_module import AMDIM  # noqa: F401
     22 from pl_bolts.models.self_supervised.byol.byol_module import BYOL  # noqa: F401
     23 from pl_bolts.models.self_supervised.cpc.cpc_module import CPC_v2  # noqa: F401

/mounts/work/jabbar/bin/anaconda3/envs/barlowbert/lib/python3.8/site-packages/pl_bolts/models/self_supervised/amdim/__init__.py in <module>
----> 1 from pl_bolts.models.self_supervised.amdim.amdim_module import AMDIM  # noqa: F401
      2 from pl_bolts.models.self_supervised.amdim.networks import AMDIMEncoder  # noqa: F401
      3 from pl_bolts.models.self_supervised.amdim.transforms import (  # noqa: F401
      4     AMDIMEvalTransformsCIFAR10,
      5     AMDIMEvalTransformsImageNet128,

/mounts/work/jabbar/bin/anaconda3/envs/barlowbert/lib/python3.8/site-packages/pl_bolts/models/self_supervised/amdim/amdim_module.py in <module>
     11 from pl_bolts.models.self_supervised.amdim.datasets import AMDIMPretraining
     12 from pl_bolts.models.self_supervised.amdim.networks import AMDIMEncoder
---> 13 from pl_bolts.utils.self_supervised import torchvision_ssl_encoder
     14 
     15 

ImportError: cannot import name 'torchvision_ssl_encoder' from partially initialized module 'pl_bolts.utils.self_supervised' (most likely due to a circular import) (/mounts/work/jabbar/bin/anaconda3/envs/barlowbert/lib/python3.8/site-packages/pl_bolts/utils/self_supervised.py)

@Borda Borda added bug Something isn't working and removed fix fixing issues... labels Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed Priority High priority task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants