Pytorch Faster R-CNN size mismatch errors in testing
there!
When running test_net.py in pytorch1.0 Faster R-CNN 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 errors 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 &quot;/home/ubuntu/users/fasterrcnn/faster-rcnn.pytorch-pytorch-1.0/demo.py&quot;, line 205, in &lt;module&gt;
    fasterRCNN.load_state_dict(checkpoint['model'])
  File &quot;/home/ubuntu/users/anaconda3/envs/fasterrcnn/lib/python3.6/site-packages/torch/nn/modules/module.py&quot;, line 769, in load_state_dict
    self.__class__.__name__, &quot;\n\t&quot;.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

And here is my envs:
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
blas                      1.0                         mkl    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
bzip2                     1.0.8                h7b6447c_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
ca-certificates           2020.1.1                      0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cairo                     1.14.12              h8948797_3    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
certifi                   2020.4.5.1               py36_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
cffi                      1.14.0           py36he30daa8_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
cuda100                   1.0                           0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
cycler                    0.10.0                   py36_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
cython                    0.29.17          py36he6710b0_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
dbus                      1.13.14              hb2f20db_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
easydict                  1.9                        py_0    https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge
expat                     2.2.6                he6710b0_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
faster-rcnn               0.1                       dev_0    &lt;develop&gt;
ffmpeg                    4.0                  hcdf2ecd_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
fontconfig                2.13.0               h9420a91_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
freeglut                  3.0.0                hf484d3e_5    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
freetype                  2.9.1                h8a8886c_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
glib                      2.63.1               h3eb4bd4_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
graphite2                 1.3.13               h23475e2_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
gst-plugins-base          1.14.0               hbbd80ab_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
gstreamer                 1.14.0               hb31296c_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
harfbuzz                  1.8.8                hffaf4a1_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
hdf5                      1.10.2               hba1933b_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
icu                       58.2                 he6710b0_3    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
intel-openmp              2020.1                      217    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
jasper                    2.0.14               h07fcdf6_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
jpeg                      9b                   h024ee3a_2    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
kiwisolver                1.2.0            py36hfd86e86_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
ld_impl_linux-64          2.33.1               h53a641e_7    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libedit                   3.1.20181209         hc058e9b_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libffi                    3.3                  he6710b0_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libgcc-ng                 9.1.0                hdf63c60_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libgfortran-ng            7.3.0                hdf63c60_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libglu                    9.0.0                hf484d3e_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libopencv                 3.4.2                hb342d67_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libopus                   1.3.1                h7b6447c_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libpng                    1.6.37               hbc83047_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libprotobuf               3.11.4               hd408876_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libstdcxx-ng              9.1.0                hdf63c60_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libtiff                   4.1.0                h2733197_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libuuid                   1.0.3                h1bed415_2    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libvpx                    1.7.0                h439df22_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
libxcb                    1.13                 h1bed415_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
libxml2                   2.9.9                hea5a465_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
matplotlib                3.1.3                    py36_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
matplotlib-base           3.1.3            py36hef1b27d_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
mkl                       2020.1                      217    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
mkl-service               2.3.0            py36he904b0f_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
mkl_fft                   1.0.15           py36ha843d7b_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
mkl_random                1.1.1            py36h0573a6f_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
ncurses                   6.2                  he6710b0_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
ninja                     1.9.0            py36hfd86e86_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
numpy                     1.18.1           py36h4f9e942_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
numpy-base                1.18.1           py36hde5b4d6_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
olefile                   0.46                     py36_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
opencv                    3.4.2            py36h6fd60c2_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
openssl                   1.1.1g               h7b6447c_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pcre                      8.43                 he6710b0_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
pillow                    7.1.2            py36hb39fc2d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pip                       20.0.2                   py36_3    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
pixman                    0.38.0               h7b6447c_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
protobuf                  3.11.4           py36he6710b0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
py-opencv                 3.4.2            py36hb342d67_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
pycparser                 2.20                       py_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
pyparsing                 2.4.7                      py_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
pyqt                      5.9.2            py36h05f1152_2    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
python                    3.6.10               h7579374_2    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
python-dateutil           2.8.1                      py_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
pytorch                   1.0.0           py3.6_cuda10.0.130_cudnn7.4.1_1  [cuda100]  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
pyyaml                    5.3.1            py36h7b6447c_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
qt                        5.9.7                h5867ecd_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
readline                  8.0                  h7b6447c_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
scipy                     1.2.1            py36h7c811a0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
setuptools                46.4.0                   py36_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
sip                       4.19.8           py36hf484d3e_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
six                       1.14.0                   py36_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
sqlite                    3.31.1               h62c20be_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
tensorboardx              2.0                        py_0    conda-forge
tk                        8.6.8                hbc83047_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
torchvision               0.2.0            py36h17b6947_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
tornado                   6.0.4            py36h7b6447c_1    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
wheel                     0.34.2                   py36_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
xz                        5.2.5                h7b6447c_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
yaml                      0.1.7                had09818_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
zlib                      1.2.11               h7b6447c_3    https://mirrors.ustc.edu.cn/anaconda/pkgs/main
zstd                      1.3.7                h0b5b093_0    https://mirrors.ustc.edu.cn/anaconda/pkgs/main

I tried the most useful way described here:
solution1
to __C.ANCHOR_SCALES = [4,8,16,32].

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

But still don't work for me.
Anyone help?

It says your model doesn't fit the pre-trained parameters you want to load.

Maybe check the model you're using and the .pth file and find out if they match or what.

Or post the code of your model and let's see what's going wrong.
