mmrotate icon indicating copy to clipboard operation
mmrotate copied to clipboard

The model and loaded state dict do not match exactly[Bug]

Open jsago opened this issue 2 years ago • 2 comments

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

1.x branch https://github.com/open-mmlab/mmrotate/tree/1.x

Environment

sys.platform: win32 Python: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 05:59:00) [MSC v.1929 64 bit (AMD64)] CUDA available: True numpy_random_seed: 2147483648 GPU 0: NVIDIA GeForce GTX 1650 CUDA_HOME: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1 NVCC: Cuda compilation tools, release 10.1, V10.1.24 MSVC: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.29.30145 版 GCC: n/a PyTorch: 1.8.0+cu101 PyTorch compiling details: PyTorch built with:

  • C++ Version: 199711
  • MSVC 192829337
  • Intel(R) Math Kernel Library Version 2020.0.2 Product Build 20200624 for Intel(R) 64 architecture applications
  • Intel(R) MKL-DNN v1.7.0 (Git Hash 7aed236906b1f7a05c0917e5257a1af05e9ff683)
  • OpenMP 2019
  • CPU capability usage: AVX2
  • CUDA Runtime 10.1
  • NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;a rch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  • CuDNN 7.6.4
  • Magma 2.5.4
  • Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=10.1, CUDNN_VERSION=7.6.4, CXX_COMPILER=C:/w/b/windows/tmp_bin/sccache-cl.exe, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -DUSE_PTHREADPOOL -openmp:experimental -DNDEBUG -DUSE_FBGEMM -DUSE_XNNPACK, LAPACK_INFO=mkl, PERF _WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.8.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OF F, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON,

TorchVision: 0.9.0+cu101 OpenCV: 4.6.0 MMEngine: 0.3.1 MMRotate: 1.0.0rc0+unknown

Reproduces the problem - code sample

base = [ '../base/datasets/hrsc.py', '../base/schedules/schedule_1x.py', '../base/default_runtime.py' ] angle_version = 'le90'

model = dict( type='mmdet.RetinaNet', data_preprocessor=dict( type='mmdet.DetDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_size_divisor=32, boxtype2tensor=False), backbone=dict( type='mmdet.ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=1, norm_cfg=dict(type='BN', requires_grad=True), norm_eval=True, style='pytorch', init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')), neck=dict( type='mmdet.FPN', in_channels=[256, 512, 1024, 2048], out_channels=256, start_level=1, add_extra_convs='on_input', num_outs=5), bbox_head=dict( type='mmdet.RetinaHead', num_classes=1, #修改过 in_channels=256, stacked_convs=4, feat_channels=256, anchor_generator=dict( type='FakeRotatedAnchorGenerator', angle_version=angle_version, octave_base_scale=4, scales_per_octave=3, ratios=[1.0, 0.5, 2.0], strides=[8, 16, 32, 64, 128]), bbox_coder=dict( type='DeltaXYWHTRBBoxCoder', angle_version=angle_version, norm_factor=None, edge_swap=True, proj_xy=True, target_means=(.0, .0, .0, .0, .0), target_stds=(1.0, 1.0, 1.0, 1.0, 1.0)), loss_cls=dict( type='mmdet.FocalLoss', use_sigmoid=True, gamma=2.0, alpha=0.25, loss_weight=1.0), loss_bbox=dict(type='mmdet.L1Loss', loss_weight=1.0)), train_cfg=dict( assigner=dict( type='mmdet.MaxIoUAssigner', pos_iou_thr=0.5, neg_iou_thr=0.4, min_pos_iou=0, ignore_iof_thr=-1, iou_calculator=dict(type='RBboxOverlaps2D')), sampler=dict( type='mmdet.PseudoSampler'), # Focal loss should use PseudoSampler allowed_border=-1, pos_weight=-1, debug=False), test_cfg=dict( nms_pre=2000, min_bbox_size=0, score_thr=0.05, nms=dict(type='nms_rotated', iou_threshold=0.1), max_per_img=2000))

train_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args={{base.file_client_args}}), dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict(type='mmdet.Resize', scale=(800, 512), keep_ratio=True), dict( type='mmdet.RandomFlip', prob=0.75, direction=['horizontal', 'vertical', 'diagonal']), dict(type='RandomRotate', prob=0.5, angle_range=180), dict(type='mmdet.PackDetInputs') ]

train_dataloader = dict(dataset=dict(pipeline=train_pipeline))

Reproduces the problem - command or script

python tool/train.py --config ../configs/rotated_retinanet/rotated-retinanet-rbox-le90_r50_fpn_rr-6x_hrsc.py --work-dir ../my_checkpoints/run00_rr_hrsc_mini_300

Reproduces the problem - error message

mmengine - WARNING - The model and loaded state dict do not match exactly

unexpected key in source state_dict: fc.weight, fc.bias

11/14 22:21:28 - mmengine - INFO - Checkpoints will be saved to C:\Users\Jsa\Desktop\Scientific_Research\mmrotate-1.0.0rc0\my_checkpoints\run00_rr_hrsc_mini_300. C:\Users\Jsa\Desktop\Scientific_Research\mmrotate-1.0.0rc0\mmrotate\structures\bbox\rotated_boxes.py:192: UserWarning: The clip function does nothing in RotatedBoxes. warnings.warn('The clip function does nothing in RotatedBoxes.') C:\Users\Jsa\Desktop\Scientific_Research\mmrotate-1.0.0rc0\mmrotate\structures\bbox\rotated_boxes.py:192: UserWarning: The clip function does nothing in RotatedBoxes. warnings.warn('The clip function does nothing in RotatedBoxes.') C:\Users\Jsa\Desktop\Scientific_Research\mmrotate-1.0.0rc0\mmrotate\structures\bbox\rotated_boxes.py:192: UserWarning: The clip function does nothing in RotatedBoxes. warnings.warn('The clip function does nothing in RotatedBoxes.') C:\Users\Jsa\Desktop\Scientific_Research\mmrotate-1.0.0rc0\mmrotate\structures\bbox\rotated_boxes.py:192: UserWarning: The clip function does nothing in RotatedBoxes. warnings.warn('The clip function does nothing in RotatedBoxes.')

Additional information

I have not modified any configuration. I use a part of the hrsc2016 dataset, and an error is reported that mmengine - WARNING - The model and loaded state dict do not match exactly unexpected key in source state_dict: fc.weight, fc.bias C:\Users\Jsa\Desktop\Scientific_Research\mmrotate-1.0.0rc0\mmrotate\structures\bbox\rotated_boxes.py:192: UserWarning: The clip function does nothing in RotatedBoxes. The most important thing is that although the loss has been decreasing, the map has always been 0. I trained 300 epochs

jsago avatar Nov 14 '22 14:11 jsago

Where is the ../my_checkpoints/run00_rr_hrsc_mini_300 come form? Is it trained by mmrotate 0.x ?

In mmrotate 0.x, the angle of anchor is always 0, which is incorrect. So in 1.x we refactor the anchor generator.

https://github.com/open-mmlab/mmrotate/blob/bc1ced4cafdc8d62305958512b0195d822ff6c7f/mmrotate/core/anchor/anchor_generator.py#L40-L44

In 1.x, the angle of anchor will change accoreding to the angle version.

https://github.com/open-mmlab/mmrotate/blob/e64ab240c1fdadae9141dd20aae3b8d91ae9aa3c/mmrotate/models/task_modules/prior_generators/anchor_generator.py#L56-L58

If you want to use 0. x model weights in 1. x, you need to delete angle_version in anchor_generator https://github.com/open-mmlab/mmrotate/blob/766185ed317f99379cb14035a6f9e5cf8a5340ad/configs/rotated_retinanet/rotated-retinanet-rbox-le90_r50_fpn_rr-6x_hrsc.py#L41

zytx121 avatar Nov 15 '22 07:11 zytx121

../my_checkpoints/run00_rr_hrsc_mini_300 is the directory where I saved the training weights. I used the official resnet pre training weights instead of my own training weights. The environment I used was mmrotate 1.0.0rc0, and no configuration was changed

jsago avatar Nov 16 '22 02:11 jsago

../my_checkpoints/run00_rr_hrsc_mini_300 is the directory where I saved the training weights. I used the official resnet pre training weights instead of my own training weights. The environment I used was mmrotate 1.0.0rc0, and no configuration was changed.

We will update all training weights for 1.x later.

zytx121 avatar Nov 18 '22 01:11 zytx121