Cannot import name 'ResNet50_Weights' from 'torchvision.models.resnet'
I was previously loading a ResNet model with the ResNet50_Weights parameter successfully, but then suddenly I started getting the following error:
Traceback (most recent call last):
  File &quot;splitting_models.py&quot;, line 3, in &lt;module&gt;
    from torchvision.models.resnet import ResNet50_Weights
ImportError: cannot import name 'ResNet50_Weights' from 'torchvision.models.resnet' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torchvision/models/resnet.py)

Here is the import:
from torchvision.models import ResNet50_Weights

How could I go about fixing this?
PyTorch version: 1.2.0
TorchVision version: 0.4.0
EDIT
Upgrading using
pip install --upgrade torch torchvision

to the following versions fixed the issue:
PyTorch version: 1.12.0
TorchVision version: 0.13.0

The problem took me some days to solve it.
Before running a code containing the Pytorch models, make sure you are connected to a stable network. This because for the first time when you are running a Pytorch model such resnet50, alexnet, resnet18 it downloads its' functionalities, so incase of installation error it caches its downloads and draws such error, if you try to re-run. To solve the problem locate where the cache file is, do delete it and try to re-run the code having a stable network.
for my case:
C:\Users\user/.cache\torch\hub\checkpoints\resnet18-f37072fd.pth

this where the is cached file was, delete it and try to re-run having a stable network.
I hope it will help.
Thanks regards,
