KeyError when load pretrained densenet161

I’m using torch 0.4.0a0+5945f3a, torchvision 0.2.0, python3.6.
I get a KeyError when load densenet161.
The code is

import torchvision.models as models
net = models.densenet161(pretrained=True)

And the Error is

File “”, line 178, in
File “”, line 150, in main
net = models.densenet161(pretrained=True)
File “/root/anaconda3/lib/python3.6/site-packages/torchvision-0.2.0-py3.6.egg/torchvision/models/”, line 68, in densenet161
File “/root/anaconda3/lib/python3.6/site-packages/torchvision-0.2.0-py3.6.egg/torchvision/models/”, line 142, in init
File “/root/anaconda3/lib/python3.6/site-packages/torchvision-0.2.0-py3.6.egg/torchvision/models/”, line 98, in init
File “/root/anaconda3/lib/python3.6/site-packages/torchvision-0.2.0-py3.6.egg/torchvision/models/”, line 77, in init
File “/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/”, line 169, in add_module
raise KeyError(“module name can’t contain “.””)
KeyError: ‘module name can’t contain “.”’

Hi, have you solve the problem? I came across the same KeyError, too. I’m on Windows 10 with compiled from source pytorch, version ‘0.5.0a0+7a3c38a’.

I think this should be the reason.
However, it seems impossible to load previous model weights after this update.

Hi Jet ,
I have the same issue too. Will installing an older version of torchvision help to make it work for now ?


I tried it on my windows machine and it works.
I’m running pytorch 0.4 on windows installed from pip, and torchvision version is 0.2.1

Thank you !
It works now ! I was in torchvision 0.2.0 and it threw me the above error.