jwyang / faster-rcnn.pytorch

A faster pytorch implementation of faster r-cnn
MIT License
7.66k stars 2.33k forks source link

size mismatch #803

Closed dreamedrainbow closed 4 years ago

dreamedrainbow commented 4 years ago

Hi,there! When running test_net.py and demo.py on coco dataset with faster_rcnn_1_10_9771.pth(the pretrained resnet101 model on coco dataset provided by jwyang), I encounter the same error below :

Called with args:
Namespace(batch_size=1, cfg_file='cfgs/res101.yml', checkepoch=10, checkpoint=9771, checksession=1, class_agnostic=True, cuda=True, dataset='coco', image_dir='/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/images', load_dir='/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/models', mGPUs=True, net='res101', parallel_type=0, set_cfgs=None, vis=True, webcam_num=-1)
/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/lib/model/utils/config.py:374: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  yaml_cfg = edict(yaml.load(f))
Using config:
{'ANCHOR_RATIOS': [0.5, 1, 2],
 'ANCHOR_SCALES': [4, 8, 16, 32],
 'CROP_RESIZE_WITH_MAX_POOL': False,
 'CUDA': False,
 'DATA_DIR': '/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/data',
 'DEDUP_BOXES': 0.0625,
 'EPS': 1e-14,
 'EXP_DIR': 'res101',
 'FEAT_STRIDE': [16],
 'GPU_ID': 0,
 'MATLAB': 'matlab',
 'MAX_NUM_GT_BOXES': 20,
 'MOBILENET': {'DEPTH_MULTIPLIER': 1.0,
               'FIXED_LAYERS': 5,
               'REGU_DEPTH': False,
               'WEIGHT_DECAY': 4e-05},
 'PIXEL_MEANS': array([[[102.9801, 115.9465, 122.7717]]]),
 'POOLING_MODE': 'align',
 'POOLING_SIZE': 7,
 'RESNET': {'FIXED_BLOCKS': 1, 'MAX_POOL': False},
 'RNG_SEED': 3,
 'ROOT_DIR': '/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0',
 'TEST': {'BBOX_REG': True,
          'HAS_RPN': True,
          'MAX_SIZE': 1000,
          'MODE': 'nms',
          'NMS': 0.3,
          'PROPOSAL_METHOD': 'gt',
          'RPN_MIN_SIZE': 16,
          'RPN_NMS_THRESH': 0.7,
          'RPN_POST_NMS_TOP_N': 300,
          'RPN_PRE_NMS_TOP_N': 6000,
          'RPN_TOP_N': 5000,
          'SCALES': [600],
          'SVM': False},
 'TRAIN': {'ASPECT_GROUPING': False,
           'BATCH_SIZE': 128,
           'BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
           'BBOX_NORMALIZE_MEANS': [0.0, 0.0, 0.0, 0.0],
           'BBOX_NORMALIZE_STDS': [0.1, 0.1, 0.2, 0.2],
           'BBOX_NORMALIZE_TARGETS': True,
           'BBOX_NORMALIZE_TARGETS_PRECOMPUTED': True,
           'BBOX_REG': True,
           'BBOX_THRESH': 0.5,
           'BG_THRESH_HI': 0.5,
           'BG_THRESH_LO': 0.0,
           'BIAS_DECAY': False,
           'BN_TRAIN': False,
           'DISPLAY': 20,
           'DOUBLE_BIAS': False,
           'FG_FRACTION': 0.25,
           'FG_THRESH': 0.5,
           'GAMMA': 0.1,
           'HAS_RPN': True,
           'IMS_PER_BATCH': 1,
           'LEARNING_RATE': 0.001,
           'MAX_SIZE': 1000,
           'MOMENTUM': 0.9,
           'PROPOSAL_METHOD': 'gt',
           'RPN_BATCHSIZE': 256,
           'RPN_BBOX_INSIDE_WEIGHTS': [1.0, 1.0, 1.0, 1.0],
           'RPN_CLOBBER_POSITIVES': False,
           'RPN_FG_FRACTION': 0.5,
           'RPN_MIN_SIZE': 8,
           'RPN_NEGATIVE_OVERLAP': 0.3,
           'RPN_NMS_THRESH': 0.7,
           'RPN_POSITIVE_OVERLAP': 0.7,
           'RPN_POSITIVE_WEIGHT': -1.0,
           'RPN_POST_NMS_TOP_N': 2000,
           'RPN_PRE_NMS_TOP_N': 12000,
           'SCALES': [600],
           'SNAPSHOT_ITERS': 5000,
           'SNAPSHOT_KEPT': 3,
           'SNAPSHOT_PREFIX': 'res101_faster_rcnn',
           'STEPSIZE': [30000],
           'SUMMARY_INTERVAL': 180,
           'TRIM_HEIGHT': 600,
           'TRIM_WIDTH': 600,
           'TRUNCATED': False,
           'USE_ALL_GT': True,
           'USE_FLIPPED': True,
           'USE_GT': False,
           'WEIGHT_DECAY': 0.0001},
 'USE_GPU_NMS': True}
load checkpoint /home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/models/res101/coco/faster_rcnn_1_10_9771.pth
Traceback (most recent call last):
  File "/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/demo.py", line 205, in <module>
    fasterRCNN.load_state_dict(checkpoint['model'])
  File "/home/ubuntu/users/anaconda3/envs/fasterrcnn/lib/python3.6/site-packages/torch/nn/modules/module.py", line 769, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for resnet:
    **size mismatch for RCNN_bbox_pred.weight:** copying a param with shape torch.Size([324, 2048]) from checkpoint, the shape in current model is torch.Size([4, 2048]).
    **size mismatch for RCNN_bbox_pred.bias**: copying a param with shape torch.Size([324]) from checkpoint, the shape in current model is torch.Size([4]).

Process finished with exit code 1

I tried the most useful way described here: image to __C.ANCHOR_SCALES = [4,8,16,32] also tried modifying the classes of pascal voc dataset to the classes of coco datasets

coco_classes = np.asarray(["__background__",
                             "person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
                             "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep",
                             "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee",
                             "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard",
                             "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich",
                             "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "couch", "potted plant", "bed",
                             "dining table", "toilet", "tv", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven",
                             "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier",
                             "toothbrush"])

but the error still here. Anyone help?

Blahblah-Z commented 3 years ago

Hello, I got this issue as well when I use my own .pth file (pretrained vgg16 model on VOC datasets). And I changed some layers of the original vgg16 model structure. Have you solved this problem already? I would so appreciate it if you can share your experience with me.