open-mmlab / mmsegmentation

OpenMMLab Semantic Segmentation Toolbox and Benchmark.
https://mmsegmentation.readthedocs.io/en/main/
Apache License 2.0
8.25k stars 2.61k forks source link

Segformer checkpoint loading error #3558

Open BhJia opened 9 months ago

BhJia commented 9 months ago

Hi, I have encoutered a problem while loading the checkpoint of Segformer model. Specifically, the model and loaded state dict do not match exactly. The error messages are as below:

Loads checkpoint by local backend from path: checkpoints/mit_b5_20220624-658746d9.pth The model and loaded state dict do not match exactly unexpected key in source state_dict:..... missing keys in source state_dict:... Traceback (most recent call last): File "demo/artifact_detection.py", line 320, in main() File "demo/artifact_detection.py", line 215, in main model = init_model(args.config, args.checkpoint, device=args.device) File "mmsegmentation/mmseg/apis/inference.py", line 62, in init_model dataset_meta = checkpoint['meta'].get('dataset_meta', None) KeyError: 'meta'

I have searched the previous issues and found issue #1303 which fixed the similar problem by uploading the modified models. Would you please checking the checkpoints of Segformer and fix the problem? Thanks a lot!

BhJia commented 9 months ago

I have fixed the problem. The reason of it is that the checkpoint provided by the link in the config file may be of another version which is incompatible with the config file. Simply downloading the one provided in the Readme file in mmsegmentation/configs/segformer works.