question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot import name 'torchvision_ssl_encoder'

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bordacommented, 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…

0reactions
MaveriQcommented, 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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ImportError: Cannot Import Name in Python - Rollbar
The Python ImportError: cannot import name error occurs when an imported class is not accessible or is in a circular dependency.
Read more >
What can I do about "ImportError: Cannot import name X" or ...
physics.py is imported from entity before class Ent is defined and physics tries to import entity that is already initializing. Remove the dependency...
Read more >
cannot import name "CLIPVisionModelWithProjection ... - GitHub
I'm not familiar with the development environment or the code, but it seems like it fails to resolve CLIPVisionModelWithProjection when importing the safety ......
Read more >
cannot import name 'sql' from 'databricks'
I am working on Databricks version 10.4 premium cluster and while importing sql from databricks module I am getting below error. cannot ......
Read more >
How do I fix the ImportError: cannot import name 'delayed'?
delay imported delayed. However, I am still getting the following error: ImportError: cannot import name 'delayed'. I appreciate your help and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found