orsic / swiftnet

GNU General Public License v3.0
251 stars 54 forks source link

state_dict load error when evaluating #38

Open BooPatienze opened 3 years ago

BooPatienze commented 3 years ago

I want to evaluate a SPECIFIED Image using your method, how should I do?

  1. After downloading two file "swiftnet_pyr_cs.pt" and "swiftnet_ss_cs.pt" from the link https://drive.google.com/drive/folders/1DqX-N-nMtGG9QfMY_cKtULCKTfEuV4WT you give in README.md

  2. I edit the file configs/rn18_single_scale.py to switch the evaluating to True and load the pre-trained model in this way:

    67 if evaluating:
    68    model.load_state_dict(torch.load('weights/swiftnet_ss_cs.pt'))
    69     # model.load_state_dict(torch.load('weights/rn18_single_scale/model_best.pt'))
    70 else:
    71     model.criterion = SemsegCrossEntropy(num_classes=num_classes, ignore_id=ignore_id)
    72     lr = 4e-4
    73     lr_min = 1e-6
    74     fine_tune_factor = 4
    75     weight_decay = 1e-4
    76     epochs = 250
  3. then run this cmd for evaluation: python eval.py configs/rn18_single_scale.py but I got some state_dict errors:

    RuntimeError: Error(s) in loading state_dict for SemsegModel:
        Missing key(s) in state_dict: "backbone.img_mean", "backbone.img_std", "logits.conv.bias".
        size mismatch for logits.conv.weight: copying a param with shape torch.Size([19, 128, 3, 3]) from checkpoint, the shape in current model is torch.Size([19, 128, 1, 1]).
  4. So I change the pre-trained model I ever load in configs/rn18_single_scale.py _from swiftnet_ss_cs.pt to swiftnet_pyr_cs.pt_ and then run last step: 3, I still got some state_dict error:

    RuntimeError: Error(s) in loading state_dict for SemsegModel:
        Missing key(s) in state_dict:
        ……
        Unexpected key(s) in state_dict:
        ……
        size mismatch for logits.conv.weight: copying a param with shape torch.Size([19, 128, 3, 3]) from checkpoint, the shape in current model is torch.Size([19, 128, 1, 1]).

So, how should I do to evaluate a Specified Image?

isunLt commented 3 years ago

Same error