Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Error(s) in loading state_dict for Generalized_RCNN: #10

Open
aligoglos opened this issue Dec 25, 2020 · 0 comments
Open

Comments

@aligoglos
Copy link

aligoglos commented Dec 25, 2020

Hi,
Thanks for your work,
I've tried to run minimal demo code I wrote but i got this error :

Traceback (most recent call last):
  File "demo.py", line 33, in <module>
    main()
  File "demo.py", line 17, in main
    load_weights(model, w)
  File "D:\Artificial Intelligence\HumanDetection_Tracking\_Human Parsing\RP-R-CNN-master\utils\checkpointer.py", line 29, in load_weights
    model.load_state_dict(model_state_dict)
  File "C:\Users\127051\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 1052, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Generalized_RCNN:
        size mismatch for RPN.anchor_generator.cell_anchors.0: copying a param with shape torch.Size([3, 4]) from checkpoint, the shape in current model is torch.Size([15, 4]).
        size mismatch for RPN.head.conv.weight: copying a param with shape torch.Size([256, 256, 3, 3]) from checkpoint, the shape in current model is torch.Size([2048, 2048, 3, 3]).
        size mismatch for RPN.head.conv.bias: copying a param with shape torch.Size([256]) from checkpoint, the shape in current model is torch.Size([2048]).
        size mismatch for RPN.head.cls_logits.weight: copying a param with shape torch.Size([3, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([15, 2048, 1, 1]).
        size mismatch for RPN.head.cls_logits.bias: copying a param with shape torch.Size([3]) from checkpoint, the shape in current model is torch.Size([15]).
        size mismatch for RPN.head.bbox_pred.weight: copying a param with shape torch.Size([12, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([60, 2048, 1, 1]).
        size mismatch for RPN.head.bbox_pred.bias: copying a param with shape torch.Size([12]) from checkpoint, the shape in current model is torch.Size([60]).

I downloaded R-50-FPN on CIHP
My minimal demo code :

import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import torch
from torchvision import transforms
from rcnn.modeling.model_builder import Generalized_RCNN
from utils.checkpointer import get_weights, load_weights
from rcnn.core.config import cfg
from utils.net import convert_bn2affine_model
import cv2
import glob
import rcnn.core.test as rcnn_test

def main():
	model = Generalized_RCNN(is_train=False)
	w = get_weights('./cfgs/CIHP/e2e_rp_rcnn_R-50-FPN_6x_ms.yaml', './weights/model_latest.pth')
	load_weights(model, w)
	if cfg.MODEL.BATCH_NORM == 'freeze':
		model = convert_bn2affine_model(model)
	model.eval()
	model.to(torch.device(cfg.DEVICE))
	paths = sorted(glob.glob('./Inputs' + '/*'))
	for path in img_path_l:
		image = cv2.imread(path)
		if ~(image is None):
			img = transforms.ToTensor()(image)
			with torch.no_grad():
				result, features = rcnn_test.im_detect_bbox(model, img)
				result = rcnn_test.im_detect_mask(model, result, features)
				print(result)

if __name__ == '__main__':
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant