kaiwang960112 / Self-Cure-Network

This is a novel and easy method for annotation uncertainties.
409 stars 96 forks source link

预训练模型load的参数名称不同,value不能对接 #49

Closed 7109029214 closed 3 years ago

7109029214 commented 3 years ago

大大您好,我是深度学习的小萌新,我目前遇到了怪问题。 。 。 Res18Feature的参数命名开头都是features...,而您预训练模型的参数命名开头都是module...,load时state_dict无法对接。想请问有其他办法吗 赞叹您

image

limingcheng0710 commented 3 years ago

大大您好,我是深度学习的小萌新,我目前遇到了怪问题。 。 。 Res18Feature的参数命名开头都是features...,而您预训练模型的参数命名开头都是module...,load时state_dict无法对接。想请问有其他办法吗 赞叹您

image

在train.py里用没问题,你是不是在test.py里用了

kaiwang960112 commented 3 years ago

你可以看下网络定义里面的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 https://github.com/kaiwang960112/Self-Cure-Network/issues/49#issuecomment-832627456, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI6LK4B5VQB42PLUEIAHRETTMEWWJANCNFSM434IWLZA .

janicelicy commented 3 years ago

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.