EfficientNet-PyTorch
EfficientNet-PyTorch copied to clipboard
AttributeError: 'NoneType' object has no attribute 'missing_keys'
trafficstars
when I run your example it comes this:
File "anaconda3/envs/sikuenv/lib/python3.6/site-packages/efficientnet_pytorch/model.py", line 196, in from_pretrained
load_pretrained_weights(model, model_name, load_fc=(num_classes == 1000))
File "anaconda3/envs/sikuenv/lib/python3.6/site-packages/efficientnet_pytorch/utils.py", line 298, in load_pretrained_weights
assert str(res.missing_keys) == str(['_fc.weight', '_fc.bias']), 'issue loading pretrained weights'
AttributeError: 'NoneType' object has no attribute 'missing_keys'
I find this source codes in my python lib:
utils.py ,line 297 ,function model.load_state_dict(state_dict, strict=False) seems return nothing, so variable "res" is NULL, mybe this caused by my torch's version
def load_pretrained_weights(model, model_name, load_fc=True):
""" Loads pretrained weights, and downloads if loading for the first time. """
state_dict = model_zoo.load_url(url_map[model_name])
if load_fc:
model.load_state_dict(state_dict)
else:
state_dict.pop('_fc.weight')
state_dict.pop('_fc.bias')
res = model.load_state_dict(state_dict, strict=False)
assert str(res.missing_keys) == str(['_fc.weight', '_fc.bias']), 'issue loading pretrained weights'
print('Loaded pretrained weights for {}'.format(model_name))
when I commented line 298,and remove variable res , it is working well again
Almost forgot. Thank you very much for your code.
@gcy506067668 hi, Can you tell me how to solve it? I have the same problem.
@gcy506067668 hi, Can you tell me how to solve it? I have the same problem. 貌似是有些torch版本model.load_state_dict函数不返回任何值,把下面的assert注释掉就可以了