question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError: Error(s) in loading state_dict for FasterRCNN

See original GitHub issue

I’ve saved a model using model.save('model_weights.pth') after a successful run.

When now attempting to load the model using the code;

from detecto.core import Model

model = Model.load('model_weights.pth', ['aboriginalflags'])

I get the error

Traceback (most recent call last):
  File "show.py", line 5, in <module>
    model = Model.load('model_weights.pth', ['aboriginalflags'])
  File "/usr/local/lib/python3.8/dist-packages/detecto/core.py", line 566, in load
    model._model.load_state_dict(torch.load(file, map_location=model._device))
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1044, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for FasterRCNN:
	size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([3, 1024]) from checkpoint, the shape in current model is torch.Size([2, 1024]).
	size mismatch for roi_heads.box_predictor.cls_score.bias: copying a param with shape torch.Size([3]) from checkpoint, the shape in current model is torch.Size([2]).
	size mismatch for roi_heads.box_predictor.bbox_pred.weight: copying a param with shape torch.Size([12, 1024]) from checkpoint, the shape in current model is torch.Size([8, 1024]).
	size mismatch for roi_heads.box_predictor.bbox_pred.bias: copying a param with shape torch.Size([12]) from checkpoint, the shape in current model is torch.Size([8]).

Ubuntu 20

(loving the lib, great work)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
smithajocommented, Sep 14, 2021

Were you able to solve the issue ? Could you share how you did it?

0reactions
SutirthaChakrabortycommented, Oct 6, 2022

image

Is it still the problem ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyTorch - RuntimeError: Error(s) in loading state_dict for VGG
The problem is that what is being saved is not the same as what is expected to be loaded. The code is trying...
Read more >
RuntimeError: Error(s) in loading state_dict for FasterRCNN
Problem description​​ RuntimeError: Error(s) in loading state_dict for FasterRCNN:Missing key(s) in state_dict: “backbone.body.conv1.weight”, “backbone.body.bn1. ...
Read more >
RuntimeError: Error(s) in loading state_dict for DataParallel
Hi, I have reimplemented the GAN for grayscale radiology data using the following Github Repo: GitHub - mdraw/BMSG-GAN at img_channels I ...
Read more >
RuntimeError: Error(s) in loading state_dict for FasterRCNN
Problem description. RuntimeError: Error(s) in loading state_dict for FasterRCNN:Missing key(s) in state_dict: “backbone.body.conv1.weight”, ...
Read more >
[Solution][Pytorch] RuntimeError: Error(s) in loading state_dict for
다를 수 있지만 저에게 있어 해당 문제는 다중 GPU를 사용하고자 torch.nn.DataParallel를 사용하면서 생긴 문제라고 판단했습니다. nn.DataParallel 모델 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found