DBPN-Pytorch icon indicating copy to clipboard operation
DBPN-Pytorch copied to clipboard

I inserted some layers into dbpn.py,and it can be trained successfully.But failed to test.

Open yangyingni opened this issue 6 years ago • 1 comments

It shows RuntimeError:Error(s) in loading state_dict for Net: Missing key(s) in state_dict:"feat0.conv.bias","feat0.conv.weight","feat0.conv.act.weight"........... Unexcepted key(s) in state_dict:"moudle.feat0.conv.weight","moudle.feat0.conv.bias"........

Can you give me some advices?Thank you very much.

yangyingni avatar Aug 23 '19 09:08 yangyingni

I'm probably a little late to the party, but let me answer this for the future wanderers. When you modify the network by adding/removing a layer or doing anything that modifies the architecture of the network, you are inherently changing the whole model itself.

Simply put, you made a new network. The state dict you're using is for the original model, and hence does not include the parameter entries for your layers. If you wish to test your modified network you will have to train it from scratch (which I wont suggest) or you can use transfer learning (which might save you a lot of time by converging to a lower loss quicker).

You may have to write your own script that initializes the weights of the original layers from the original state dict while using some other parameters initialization method (Glorot, He, Xavier initialization are some of them. Also see this) for the newer layers that you added.

Hope that helps.

shazib-summar avatar Oct 30 '20 08:10 shazib-summar