Loading pth file error

When I use this code xception model, and run it like blow

if __name__ == '__main__':
    model = xception()
    print('Done')

the error come out

RuntimeError: Error(s) in loading state_dict for Xception:
While copying the parameter named “block1.rep.0.pointwise.weight”, whose dimensions in the model are torch.Size([128, 64, 1, 1]) and whose dimensions in the checkpoint are torch.Size([128, 64]).
While copying the parameter named “block1.rep.3.pointwise.weight”, whose dimensions in the model are torch.Size([128, 128, 1, 1]) and whose dimensions in the checkpoint are torch.Size([128, 128]).
While copying the parameter named “block2.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([256, 128, 1, 1]) and whose dimensions in the checkpoint are torch.Size([256, 128]).
While copying the parameter named “block2.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([256, 256, 1, 1]) and whose dimensions in the checkpoint are torch.Size([256, 256]).
While copying the parameter named “block3.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 256, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 256]).
While copying the parameter named “block3.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block4.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block4.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block4.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block5.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block5.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block5.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block6.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block6.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block6.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block7.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block7.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block7.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block8.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block8.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block8.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block9.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block9.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block9.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block10.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block10.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block10.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block11.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block11.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block11.rep.7.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block12.rep.1.pointwise.weight”, whose dimensions in the model are torch.Size([728, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([728, 728]).
While copying the parameter named “block12.rep.4.pointwise.weight”, whose dimensions in the model are torch.Size([1024, 728, 1, 1]) and whose dimensions in the checkpoint are torch.Size([1024, 728]).
While copying the parameter named “conv3.pointwise.weight”, whose dimensions in the model are torch.Size([1536, 1024, 1, 1]) and whose dimensions in the checkpoint are torch.Size([1536, 1024]).
While copying the parameter named “conv4.pointwise.weight”, whose dimensions in the model are torch.Size([2048, 1536, 1, 1]) and whose dimensions in the checkpoint are torch.Size([2048, 1536]).

I don’t know how to deal with it , looking forward to your reply, thank you!!!

I guess this basically means that the tensor defined by your model is a 4D tensor while the model you are trying to load saved the parameters as 2D tensor.
If you can unsqueeze the pretrained tensor and make it a 4D tensor. I think it will work

Thanks a lot!!! it realy solve this issue.

Happy to learn because of you.