Error in Loading dict


(Jaideep Valani) #1

Hi ,i
Added a new layer to pre trained model.
But when i do a fit i get below error.
How do i oercome this error ,i assumed weights should get auto initialized for anynewly added layer

Error(s) in loading state_dict for Sequential:
Missing key(s) in state_dict: “1.x_conv.weight”, “1.x_conv.bias”, “1.tr_conv.weight”, “1.tr_conv.bias”, “1.bn.weight”, “1.bn.bias”, “1.bn.running_mean”, “1.bn.running_var”, “1.fc.weight”, “1.fc.bias”.
Unexpected key(s) in state_dict: “1.2.weight”, “1.2.bias”, “1.2.running_mean”, “1.2.running_var”, “1.2.num_batches_tracked”, “1.4.weight”, “1.4.bias”, “1.6.weight”, “1.6.bias”, “1.6.running_mean”, “1.6.running_var”, “1.6.num_batches_tracked”, “1.8.weight”, “1.8.bias”.


(Anuvabh) #2

I think by default load_state_dict requires a strict matching of parameter names. Try loading with model.load_state_dict(state_dict, strict=False)