brandleyzhou / DIFFNet

[BMVC 2021] ''Self-Supervised Monocular Depth Estimation with Internal Feature Fusion''
109 stars 21 forks source link

Missing Keys in Pretrained Weights #25

Closed ldkong1205 closed 1 year ago

ldkong1205 commented 1 year ago

Hi @brandleyzhou, thank you for your great work!

I met the following problem when testing your pretrained models:

Exception has occurred: RuntimeError
Error(s) in loading state_dict for HRDepthDecoder:
    Missing key(s) in state_dict: "convs.up_x9_0.conv.conv.weight", "convs.up_x9_0.conv.conv.bias", "convs.up_x9_1.conv.conv.weight", "convs.up_x9_1.conv.conv.bias", "convs.72.ca.fc.0.weight", "convs.72.ca.fc.2.weight", "convs.72.conv_se.weight", "convs.72.conv_se.bias", "convs.36.ca.fc.0.weight", "convs.36.ca.fc.2.weight", "convs.36.conv_se.weight", "convs.36.conv_se.bias", "convs.18.ca.fc.0.weight", "convs.18.ca.fc.2.weight", "convs.18.conv_se.weight", "convs.18.conv_se.bias", "convs.9.ca.fc.0.weight", "convs.9.ca.fc.2.weight", "convs.9.conv_se.weight", "convs.9.conv_se.bias", "convs.dispConvScale0.conv.weight", "convs.dispConvScale0.conv.bias", "convs.dispConvScale1.conv.weight", "convs.dispConvScale1.conv.bias", "convs.dispConvScale2.conv.weight", "convs.dispConvScale2.conv.bias", "convs.dispConvScale3.conv.weight", "convs.dispConvScale3.conv.bias", "decoder.0.conv.conv.weight", "decoder.0.conv.conv.bias", "decoder.1.conv.conv.weight", "decoder.1.conv.conv.bias", "decoder.2.ca.fc.0.weight", "decoder.2.ca.fc.2.weight", "decoder.2.conv_se.weight", "decoder.2.conv_se.bias", "decoder.3.ca.fc.0.weight", "decoder.3.ca.fc.2.weight", "decoder.3.conv_se.weight", "decoder.3.conv_se.bias", "decoder.4.ca.fc.0.weight", "decoder.4.ca.fc.2.weight", "decoder.4.conv_se.weight", "decoder.4.conv_se.bias", "decoder.5.ca.fc.0.weight", "decoder.5.ca.fc.2.weight", "decoder.5.conv_se.weight", "decoder.5.conv_se.bias", "decoder.6.conv.weight", "decoder.6.conv.bias", "decoder.7.conv.weight", "decoder.7.conv.bias", "decoder.8.conv.weight", "decoder.8.conv.bias", "decoder.9.conv.weight", "decoder.9.conv.bias". 

The pretrained weights are downloaded from this repository page. Specifically, I was testing two pretrained models:

Could you please have a look at this and upload the complete models? Thanks in advance!

brandleyzhou commented 1 year ago

Hi, Thank you for your interest. I'm sorry for this confusion. Is your code up-to-date? If so, please use the weights in models/diffnet_640x192 instead.

ldkong1205 commented 1 year ago

Hi, Thank you for your interest. I'm sorry for this confusion. Is your code up-to-date? If so, please use the weights in models/diffnet_640x192 instead.

Hi @brandleyzhou, thank you for your reply! Yes, I am using the latest code and I have tried the checkpoints in models/diffnet_640x192, too, but the problem still exists. Could you please have a look? Thanks!

ldkong1205 commented 1 year ago

From my side, the encoder_dict and decoder_dict are loading the exact same number of keys, which should all belong to the encoder.

ncoder_dict = torch.load(encoder_path) if torch.cuda.is_available() else torch.load(encoder_path,map_location = 'cpu')
decoder_dict = torch.load(decoder_path) if torch.cuda.is_available() else torch.load(encoder_path,map_location = 'cpu')

Then I found that this line has a typo: the decoder_dict should load from decoder_path instead of encoder_path. I think you might want to modify this.

brandleyzhou commented 1 year ago

Yes, you are right. if you use cuda/gpu to test, the code is ok. but in the other case, the decoder would be loaded wrong weights. Thanks for pointing it out.

ldkong1205 commented 1 year ago

Yes, you are right. if you use cuda/gpu to test, the code is ok. but in the other case, the decoder would be loaded wrong weights. Thanks for pointing it out.

Right. Thanks!