MadryLab / robustness

A library for experimenting with, training and evaluating neural networks, with a focus on adversarial robustness.
MIT License
903 stars 181 forks source link

ImportError causes by `load_state_dict_from_url` #86

Closed Embeddave closed 3 years ago

Embeddave commented 3 years ago

Hi robustness devs,

I'm getting the following error:

Traceback (most recent call last):
  File "resnet50_cifar10.py", line 9, in <module>
    from robustness.datasets import DATASETS
  File "/home/ubuntu/anaconda3/envs/gard-core/lib/python3.7/site-packages/robustness/datasets.py", line 22, in <module>
    from . import imagenet_models, cifar_models
  File "/home/ubuntu/anaconda3/envs/gard-core/lib/python3.7/site-packages/robustness/imagenet_models/__init__.py", line 1, in <module>
    from .resnet import *
  File "/home/ubuntu/anaconda3/envs/gard-core/lib/python3.7/site-packages/robustness/imagenet_models/resnet.py", line 3, in <module>
    from torch.hub import load_state_dict_from_url
ImportError: cannot import name 'load_state_dict_from_url' from 'torch.hub' (/home/ubuntu/anaconda3/envs/gard-core/lib/python3.7/site-packages/torch/hub.py)

I have the latest version of robustness (1.2.1post1), pytorch 1.0.0, and torchvision 0.2.2

looks like one fix is a try-except clause? https://github.com/zhoudaxia233/EfficientUnet-PyTorch/issues/5

try:
    from torch.hub import load_state_dict_from_url
except ImportError:
    from torch.utils.model_zoo import load_url as load_state_dict_from_url
Embeddave commented 3 years ago

bug went away after upgrading pytorch to 1.6 and torchvision to 0.7

sorry, I think I might have been the victim of some weird interaction b/t conda, poetry, and pip. had to deactivate / reactivate to deal with other weird dependency issues but after doing so everything's functioning

will go ahead and close