potterhsu / easy-faster-rcnn.pytorch

An easy implementation of Faster R-CNN (https://arxiv.org/pdf/1506.01497.pdf) in PyTorch.
MIT License
165 stars 57 forks source link

Default infer.py config doesn't seem to work with "second" ResNet101 .pth #2

Closed awemcdonald closed 5 years ago

awemcdonald commented 5 years ago

Hi,

You have 2 ResNet101 .pth checkpoints (the last 2 linked under COCO2017 in the README). While I can run infer.py with my own images and get a result on the first of the two .pth files, simply changing the path to the second .pth (while keeping everything else the same), produces the below error.

Do you know what's going on here?

The default configuration seems to work just fine for the COCO2017 VGG-16 backbone as well. It's just the second of the two COCO2017 ResNet101 backbones that seems to be a problem.

Thanks.

Config: ANCHOR_RATIOS = [(1, 2), (1, 1), (2, 1)] ANCHOR_SIZES = [64, 128, 258, 512] IMAGE_MAX_SIDE = 1333 IMAGE_MIN_SIDE = 800 POOLING_MODE = Mode.ALIGN RPN_POST_NMS_TOP_N = 1000 RPN_PRE_NMS_TOP_N = 6000

Traceback (most recent call last): File "infer.py", line 115, in main() File "infer.py", line 113, in main _infer(path_to_input_image, path_to_output_image, path_to_checkpoint, dataset_name, backbone_name, prob_thresh) File "infer.py", line 24, in _infer model.load(path_to_checkpoint) File "/home/dev/easy-faster-rcnn.pytorch/model.py", line 145, in load self.load_state_dict(checkpoint['state_dict']) File "/home/theaitherapist/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 719, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for Model: size mismatch for rpn._objectness.weight: copying a param of torch.Size([24, 512, 1, 1]) from checkpoint, where the shape is torch.Size([30, 512, 1, 1]) in current model. size mismatch for rpn._objectness.bias: copying a param of torch.Size([24]) from checkpoint, where the shape is torch.Size([30]) in current model. size mismatch for rpn._transformer.weight: copying a param of torch.Size([48, 512, 1, 1]) from checkpoint, where the shape is torch.Size([60, 512, 1, 1]) in current model. size mismatch for rpn._transformer.bias: copying a param of torch.Size([48]) from checkpoint, where the shape is torch.Size([60]) in current model.

awemcdonald commented 5 years ago

Oh, an anchor size of 32 needs to be added at the beginning of the list of ANCHOR_SIZES. Adding that fixes the problem.

The need to do this is shown if you scroll to the right in the COCO2017 table, but I haven't seen it indicated anywhere else.