open-mmlab / mmrotate

OpenMMLab Rotated Object Detection Toolbox and Benchmark
https://mmrotate.readthedocs.io/en/latest/
Apache License 2.0
1.85k stars 548 forks source link

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

Closed jsago closed 1 year ago

jsago commented 1 year ago

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:

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

zytx121 commented 1 year ago

Where is the ../my_checkpoints/run00_rr_hrsc_mini_300come 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

jsago commented 1 year ago

../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

zytx121 commented 1 year ago

../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.