Purdue-M2 / Fairness-Generalization

MIT License
18 stars 1 forks source link

Issue in Loading State Dict for FairDetector: Missing Keys #6

Closed zzy1130 closed 1 week ago

zzy1130 commented 2 weeks ago

Hi, thank you very much for your work, but I still got some problems. When I directly started from the testing part, I encountered an error while trying to load the state dictionary for the FairDetector model in the test.py script. The partial error message is as follows:

RuntimeError: Error(s) in loading state_dict for FairDetector:
        Missing key(s) in state_dict: "encoder_f.last_linear.weight", "encoder_f.last_linear.bias", "encoder_f.adjust_channel.0.weight", "encoder_f.adjust_channel.0.bias", "encoder_f.adjust_channel.1.weight", "encoder_f.adjust_channel.1.bias", "encoder_f.adjust_channel.1.running_mean", "encoder_f.adjust_channel.1.running_var", "encoder_c.conv1.weight", "encoder_c.bn1.weight", "encoder_c.bn1.bias", "encoder_c.bn1.running_mean", "encoder_c.bn1.running_var", "encoder_c.conv2.weight", "encoder_c.bn2.weight", "encoder_c.bn2.bias", "encoder_c.bn2.running_mean", "encoder_c.bn2.running_var", "encoder_c.block1.skip.weight", "encoder_c.block1.skipbn.weight", "encoder_c.block1.skipbn.bias", "encoder_c.block1.skipbn.running_mean", "encoder_c.block1.skipbn.running_var", "encoder_c.block1.rep.0.conv1.weight", "encoder_c.block1.rep.0.pointwise.weight", "encoder_c.block1.rep.1.weight", "encoder_c.block1.rep.1.bias", "encoder_c.block1.rep.1.running_mean", "encoder_c.block1.rep.1.running_var", "encoder_c.block1.rep.3.conv1.weight", "encoder_c.block1.rep.3.pointwise.weight", "encoder_c.block1.rep.4.weight", "encoder_c.block1.rep.4.bias", "encoder_c.block1.rep.4.running_mean", "encoder_c.block1.rep.4.running_var", "encoder_c.block2.skip.weight", "encoder_c.block2.skipbn.weight", "encoder_c.block2.skipbn.bias", "encoder_c.block2.skipbn.running_mean"
...

for missing keys in the model, and

 Unexpected key(s) in state_dict: "encoder_f.fc.weight", "encoder_f.fc.bias". 
        size mismatch for encoder_f.block1.rep.0.pointwise.weight: copying a param with shape torch.Size([128, 64]) from checkpoint, the shape in current model is torch.Size([128, 64, 1, 1]).
        size mismatch for encoder_f.block1.rep.3.pointwise.weight: copying a param with shape torch.Size([128, 128]) from checkpoint, the shape in current model is torch.Size([128, 128, 1, 1]).
        size mismatch for encoder_f.block2.rep.1.pointwise.weight: copying a param with shape torch.Size([256, 128]) from checkpoint, the shape in current model is torch.Size([256, 128, 1, 1]).
        size mismatch for encoder_f.block2.rep.4.pointwise.weight: copying a param with shape torch.Size([256, 256]) from checkpoint, the shape in current model is torch.Size([256, 256, 1, 1]).
        size mismatch for encoder_f.block3.rep.1.pointwise.weight: copying a param with shape torch.Size([728, 256]) from checkpoint, the shape in current model is torch.Size([728, 256, 1, 1]).
        size mismatch for encoder_f.block3.rep.4.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block4.rep.1.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block4.rep.4.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block4.rep.7.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block5.rep.1.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block5.rep.4.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block5.rep.7.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block6.rep.1.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block6.rep.4.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block6.rep.7.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block7.rep.1.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
        size mismatch for encoder_f.block7.rep.4.pointwise.weight: copying a param with shape torch.Size([728, 728]) from checkpoint, the shape in current model is torch.Size([728, 728, 1, 1]).
...

for unexpected keys and checkpoint mismatch from the checkpoint.

It seems like there is a mismatch between the checkpoint you provided and the model structure. Can you suggest any solutions to this problem? Or is it originated from some other mistakes that I made? Thank you for your attention to this matter.

Purdue-M2 commented 2 weeks ago

Hi Thank you for your interest in our work. The checkpoint you loaded is for the backbone only, not the entire model, which is why you encountered such an issue.