I am trying to load models from the model zoo in Google Colab and keep getting the errors:
AttributeError: module 'torch.jit' has no attribute 'unused'
I was trying to load https://pytorch.org/hub/pytorch_vision_deeplabv3_resnet101/ and used the offical link to open in Colab yet getting this error. Even if I try to import any model from torchvision I get the same error. How do I fix this to use a pretrained model?
I tried somethings suggested elsewhere to update pytorch to nightly and the one on google colab is already nightly and 1.2.0 so I dont know what more to do.
Thanks for raising this issue!
It seems the currently linked model cannot be imported using the latest stable release (1.2.0).
However, after installing the nightly build, the model was loaded successfully in my colab notebook.
Try to run the following lines:
!pip uninstall torch -y
!pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cu100/torch_nightly.html
# Restart of runtime might be necessary
import torch
model = torch.hub.load('pytorch/vision', 'deeplabv3_resnet101', pretrained=True)
model.eval()
Good to hear it’s working!
I’m not sure which models are currently being developed, but if you are missing some important model, we might assist you in contributing it to the hub.
Hi @ptrblck, I was facing the same problem during importing torchvision, and after installing nightly build, the problem was solved. I can import any pre-trained model using your code snippet, but I also need to use other useful functions like torchvision.transforms, torchvision.utils etc. How can I load them using nightly build? Also, if there any modified way to import torchvision now?
This is most likely caused by diverged torchvision and PyTorch versions.
Based on the error message it seems you might be using a newer torchvision installation with an older PyTorch version, which doesn’t provide the torch.jit._script_if_tracing context manager.
Could you update both libs to the stable or nightly versions and rerun the code?