VainF / DeepLabV3Plus-Pytorch

Pretrained DeepLabv3 and DeepLabv3+ for Pascal VOC & Cityscapes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

running predict.py

bubaozi990414 opened this issue · comments

Thank you for sharing!What should I do if I encounter the following error when running predict.py using the pre trained model of VOC?

RuntimeError: Error(s) in loading state_dict for DeepLabV3:
Missing key(s) in state_dict: "classifier.project.0.weight", "classifier.project.1.weight", "classifier.project.1.bias", "classifier.project.1.running_mean", "classifier.project.1.running_var", "classifier.aspp.convs.0.0.weight", "classifier.aspp.convs.0.1.weight", "classifier.aspp.convs.0.1.bias", "classifier.aspp.convs.0.1.running_mean", "classifier.aspp.convs.0.1.running_var", "classifier.aspp.convs.1.0.weight", "classifier.aspp.convs.1.1.weight", "classifier.aspp.convs.1.1.bias", "classifier.aspp.convs.1.1.running_mean", "classifier.aspp.convs.1.1.running_var", "classifier.aspp.convs.2.0.weight", "classifier.aspp.convs.2.1.weight", "classifier.aspp.convs.2.1.bias", "classifier.aspp.convs.2.1.running_mean", "classifier.aspp.convs.2.1.running_var", "classifier.aspp.convs.3.0.weight", "classifier.aspp.convs.3.1.weight", "classifier.aspp.convs.3.1.bias", "classifier.aspp.convs.3.1.running_mean", "classifier.aspp.convs.3.1.running_var", "classifier.aspp.convs.4.1.weight", "classifier.aspp.convs.4.2.weight", "classifier.aspp.convs.4.2.bias", "classifier.aspp.convs.4.2.running_mean", "classifier.aspp.convs.4.2.running_var", "classifier.aspp.project.0.weight", "classifier.aspp.project.1.weight", "classifier.aspp.project.1.bias", "classifier.aspp.project.1.running_mean", "classifier.aspp.project.1.running_var", "classifier.classifier.0.weight", "classifier.classifier.1.bias", "classifier.classifier.1.running_mean", "classifier.classifier.1.running_var", "classifier.classifier.3.weight", "classifier.classifier.3.bias".
Unexpected key(s) in state_dict: "classifier.classifier.4.weight", "classifier.classifier.4.bias", "classifier.classifier.0.convs.0.0.weight", "classifier.classifier.0.convs.0.1.weight", "classifier.classifier.0.convs.0.1.bias", "classifier.classifier.0.convs.0.1.running_mean", "classifier.classifier.0.convs.0.1.running_var", "classifier.classifier.0.convs.0.1.num_batches_tracked", "classifier.classifier.0.convs.1.0.weight", "classifier.classifier.0.convs.1.1.weight", "classifier.classifier.0.convs.1.1.bias", "classifier.classifier.0.convs.1.1.running_mean", "classifier.classifier.0.convs.1.1.running_var", "classifier.classifier.0.convs.1.1.num_batches_tracked", "classifier.classifier.0.convs.2.0.weight", "classifier.classifier.0.convs.2.1.weight", "classifier.classifier.0.convs.2.1.bias", "classifier.classifier.0.convs.2.1.running_mean", "classifier.classifier.0.convs.2.1.running_var", "classifier.classifier.0.convs.2.1.num_batches_tracked", "classifier.classifier.0.convs.3.0.weight", "classifier.classifier.0.convs.3.1.weight", "classifier.classifier.0.convs.3.1.bias", "classifier.classifier.0.convs.3.1.running_mean", "classifier.classifier.0.convs.3.1.running_var", "classifier.classifier.0.convs.3.1.num_batches_tracked", "classifier.classifier.0.convs.4.1.weight", "classifier.classifier.0.convs.4.2.weight", "classifier.classifier.0.convs.4.2.bias", "classifier.classifier.0.convs.4.2.running_mean", "classifier.classifier.0.convs.4.2.running_var", "classifier.classifier.0.convs.4.2.num_batches_tracked", "classifier.classifier.0.project.0.weight", "classifier.classifier.0.project.1.weight", "classifier.classifier.0.project.1.bias", "classifier.classifier.0.project.1.running_mean", "classifier.classifier.0.project.1.running_var", "classifier.classifier.0.project.1.num_batches_tracked", "classifier.classifier.2.weight", "classifier.classifier.2.bias", "classifier.classifier.2.running_mean", "classifier.classifier.2.running_var", "classifier.classifier.2.num_batches_tracked".
size mismatch for classifier.classifier.1.weight: copying a param with shape torch.Size([256, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([256]).

Hi,

Can you share how you resolved this, I updated the dataset.py for personal dataset. But the model while it starts training gives below error -

`Device: cuda
Dataset: ebhi, Train set: 476, Val set: 120


RuntimeError Traceback (most recent call last)
Input In [6], in <cell line: 2>()
1 # deeplabv3plus_xception 10 batch size -stride 10
----> 2 DL.main()

File /host/Upgrad/Thesis/EBHI/DeepLabV3/DeepLabV3Plus-Pytorch-master/main.py:327, in main()
324 if opts.ckpt is not None and os.path.isfile(opts.ckpt):
325 # #8 (comment)
326 checkpoint = torch.load(opts.ckpt, map_location=torch.device('cpu'))
--> 327 model.load_state_dict(checkpoint["model_state"])
328 model = nn.DataParallel(model)
329 model.to(device)

File /opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py:1604, in Module.load_state_dict(self, state_dict, strict)
1599 error_msgs.insert(
1600 0, 'Missing key(s) in state_dict: {}. '.format(
1601 ', '.join('"{}"'.format(k) for k in missing_keys)))
1603 if len(error_msgs) > 0:
-> 1604 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
1605 self.class.name, "\n\t".join(error_msgs)))
1606 return _IncompatibleKeys(missing_keys, unexpected_keys)

RuntimeError: Error(s) in loading state_dict for DeepLabV3:
size mismatch for classifier.classifier.3.weight: copying a param with shape torch.Size([21, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([2, 256, 1, 1]).
size mismatch for classifier.classifier.3.bias: copying a param with shape torch.Size([21]) from checkpoint, the shape in current model is torch.Size([2])`

Solved this, the issue was due to a static checkpoint I had added to the main.py and re-running the code for some different dataset.