soeaver / RP-R-CNN

Renovating Parsing R-CNN for Accurate Multiple Human Parsing
MIT License
95 stars 9 forks source link

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

Open aligoglos opened 3 years ago

aligoglos commented 3 years ago

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()