Vision: Error when loading pretrained VGG19

Created on 18 Mar 2017  路  21Comments  路  Source: pytorch/vision

I encountered an error when loading a pretrained vgg19 model. I tried other networks like Alexnet and they're seemed fine.

I use torch==0.1.10, torchvision==0.1.7, just updated from master branch. Also, it's under Python3.6 on latest macOS.

Do anyone have any idea how this happened and can be fixed? An error message seems like complaining incompatible un-pickling.

model = models.vgg19(True)
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/site-packages/torchvision/models/vgg.py", line 141, in vgg19
model.load_state_dict(model_zoo.load_url(model_urls['vgg19']))
File "/usr/local/lib/python3.6/site-packages/torch/utils/model_zoo.py", line 57, in load_url
return torch.load(cached_file)
File "/usr/local/lib/python3.6/site-packages/torch/serialization.py", line 222, in load
return _load(f, map_location, pickle_module)
File "/usr/local/lib/python3.6/site-packages/torch/serialization.py", line 370, in _load
result = unpickler.load()
AttributeError: Can't get attribute '_rebuild_tensor' on

awaiting response

Most helpful comment

this will be fixed after updating to the pytorch release v0.1.11 on wednesday.

All 21 comments

I also note that loading vgg11 and vgg13 is fine. vgg16 and vgg19 produces the error.

what version of torch are you on?

I'm using torch==0.1.10, this is the newest one, right?

yes it is, I'll investigate and fix these checkpoints on Monday. thanks for letting me know.

Thanks!

this will be fixed after updating to the pytorch release v0.1.11 on wednesday.

Thank you very much for your quick response! I'm looking forward to it.

I encouter the same error for vgg16.

CUDA_VISIBLE_DEVICES=2 python main.py /local/cadene/data --arch vgg16 -b 20 --lr 1e-4 --pretrained
=> using pre-trained model 'vgg16'
Downloading: "https://download.pytorch.org/models/vgg16-397923af.pth" to /home/cadene/.torch/models/vgg16-397923af.pth
100.0%
Traceback (most recent call last):
  File "main.py", line 335, in <module>
    main()
  File "main.py", line 120, in main
    model = models.__dict__[args.arch](pretrained=True)
  File "build/bdist.linux-x86_64/egg/torchvision/models/vgg.py", line 124, in vgg16
    model.load_state_dict(model_zoo.load_url(model_urls['vgg16']))
  File "/home/cadene/anaconda3/envs/default/lib/python2.7/site-packages/torch/utils/model_zoo.py", line 57, in load_url
    return torch.load(cached_file)
  File "/home/cadene/anaconda3/envs/default/lib/python2.7/site-packages/torch/serialization.py", line 222, in load
    return _load(f, map_location, pickle_module)
  File "/home/cadene/anaconda3/envs/default/lib/python2.7/site-packages/torch/serialization.py", line 370, in _load
    result = unpickler.load()
AttributeError: 'module' object has no attribute '_rebuild_tensor'

@Cadene I solved the same problem by installing newest pytorch and torchvision from source.

@Cadene is this still an issue for you when using the latest pytorch?

This appears to work with the latest version of PyTorch so closing this issue. Let me know if you are still having issues.

Getting an error when trying to import inception model. Any fixes. Same with densenet. However all models of resnet loading without any issues

inception = torchvision.models.inception_v3()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'inception_v3'

@varghesealex90 this works fine in the latest version of torchvision. What version are you running as inception_v3 was added in 0.1.8

could you tell me on how to get the torchvision version.

torch__version__ returns 0.2.0.3

oki fixed it . closing the issue

Hi;

I am encountering a new problem. I am unable to load the pre-trained network.

import torchvision

a= torchvision.models.denset121(pretrained=True)
Downloading: "https://download.pytorch.org/models/densenet121-241335ed.pth" to /home/brats/.torch/models/densenet121-241335ed.pth
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/torchvision/models/densenet.py", line 28, in densenet121
model.load_state_dict(model_zoo.load_url(model_urls['densenet121']))
File "/usr/local/lib/python2.7/dist-packages/torch/utils/model_zoo.py", line 57, in load_url
_download_url_to_file(url, cached_file, hash_prefix)
File "/usr/local/lib/python2.7/dist-packages/torch/utils/model_zoo.py", line 62, in _download_url_to_file
u = urlopen(url)
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1222, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1184, in do_open
raise URLError(err)
urllib2.URLError:

import torchvision.models
from torchvision.models.vgg import model_urls

model_urls['densenet121'] = model_urls['densenet121'].replace('https://', 'http://')
densenet121= torchvision.models.densenet121(pretrained=True)

@varghesealex90 the model for densenet121 in master is located at https://download.pytorch.org/models/densenet121-a639ec97.pth which is not the one you are downloading.

In any case, this seems to work fine on my end but may be related to server name identification. Can you let me know what python version you are using?

I am using python 2.7.6 , I fixed the issue by converting https to http

@varghesealex90 I can reproduce this issue in python 2.6.7 and can be solved by using server name identification support which was added to python 2.7.9+ so you have two options:
1) install the dependencies as described here.
2) upgrade your python version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpha-gradient picture alpha-gradient  路  3Comments

Abolfazl-Mehranian picture Abolfazl-Mehranian  路  3Comments

a-maci picture a-maci  路  3Comments

martinarjovsky picture martinarjovsky  路  4Comments

datumbox picture datumbox  路  3Comments