open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.7k stars 9.48k forks source link

load from not working? #12001

Open JNaranjo-Alcazar opened 1 month ago

JNaranjo-Alcazar commented 1 month ago

Hi community, I have set the load_from flag like:

load_from = '/app/src/mmdetection/checkpoints/mask_rcnn_r50_caffe_fpn_mstrain-poly_3x_coco_bbox_mAP-0.408__segm_mAP-0.37_20200504_163245-42aa3d00.pth'

However, when training, mmdetection starts downloading weights:

2024-10-18 06:36:33,937 - mmcv - INFO - load model from: open-mmlab://detectron2/resnet50_caffe
2024-10-18 06:36:33,937 - mmcv - INFO - load checkpoint from openmmlab path: open-mmlab://detectron2/resnet50_caffe
Downloading: "https://download.openmmlab.com/pretrain/third_party/resnet50_msra-5891d200.pth" to /root/.cache/torch/hub/checkpoints/resnet50_msra-5891d200.pth
100%|███████████████████████████████████████████████████████████████████████████████████████████████████| 89.9M/89.9M [00:03<00:00, 26.1MB/s]
2024-10-18 06:36:37,815 - mmcv - WARNING - The model and loaded state dict do not match exactly

Is this behaviour expected?

Thanks in advance

PeterVennerstrom commented 1 month ago

A typical sequence of weight loading:

  1. Model object is created and init functions create weights with different random distributions.
  2. Pretrained backbone weights are loaded, overwriting the init weights. These weights may trigger the error since they may contain unused layers like the Imagenet classification layer.
  3. Load from overwrites the rest of the weights in the full network, often triggers the same do not match warning if the class number in the loaded weights does not match a custom setting.

Probably expected.