预训练模型load的参数名称不同,value不能对接
Closed this issue · 3 comments
7109029214 commented
limingcheng0710 commented
kaiwang960112 commented
你可以看下网络定义里面的keys和模型的keys,然后两个可能就差一个module. 记得把module.去掉或者加上就行了,进行字符串操作就好了
李明程 ***@***.***> 於 2021年5月5日週三 下午7:54寫道:
… 大大您好,我是深度学习的小萌新,我目前遇到了怪问题。 。 。
Res18Feature的参数命名开头都是features...,而您预训练模型的参数命名开头都是module...,load时state_dict无法对接。想请问有其他办法吗
赞叹您
[image: image]
<https://user-images.githubusercontent.com/82702399/116704177-b1d0c000-a9fd-11eb-902b-340fa7908f2e.png>
在train.py里用没问题,你是不是在test.py里用了
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#49 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI6LK4B5VQB42PLUEIAHRETTMEWWJANCNFSM434IWLZA>
.
janicelicy commented
Hello, I just checked the shapes of the weights. The last 4 of the provided pre-trained model are
module.feature.weight torch.Size([256, 512])
module.feature.bias torch.Size([256])
module.fc.weight torch.Size([87020, 256])
module.fc.bias torch.Size([87020])
but those in resnet18 are
fc.weight torch.Size([7, 512])
fc.bias torch.Size([7])
alpha.0.weight torch.Size([1, 512])
alpha.0.bias torch.Size([1])
I am wondering if I had missed anything? Thanks.