# passing weights param as string
model = torch.hub.load("pytorch/vision", "resnet18", weights= ResNet18_Weights.IMAGENET1K_V1)
File ~/.cache/torch/hub/pytorch_vision_main/hubconf.py:4, in <module>
1 # Optional list of dependencies required by the package
2 dependencies = ["torch"]
----> 4 from torchvision.models import get_model_weights, get_weight
5 from torchvision.models.alexnet import alexnet
6 from torchvision.models.convnext import convnext_base, convnext_large, convnext_small, convnext_tiny
ImportError: cannot import name 'get_model_weights' from 'torchvision.models'
I guess you might have multiple torchvision installs in your current environment and the latest one might not be picked up. Could you check the torchvision.__version__ and post the code which raises the error, please?
In : import torchvision
In : torchvision.__version__
and checked my pip freeze | grep torchvision, the terminal shows as:
I still encounter this ‘get_model_weights’ error, which is very weird. I also used another linux machine with different torch version, install a pytorch in a new conda env, pip freeze shows as followings:
and in python I confirmed the torchvision.version is ‘0.11.2+cu113’. Same error exists when I do torch.hub.load