open-mmlab / mmsegmentation

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

mmseg SwinTransformer run error #850

Closed daigang896 closed 3 years ago

daigang896 commented 3 years ago

TypeError: EncoderDecoder: SwinTransformer: init() got an unexpected keyword argument 'pretrain_style'. mmcv.version='1.3.12' mmseg.version'0.17.0' Python 3.6.13

whole code: from mmseg.apis import inference_segmentor, init_segmentor from mmcv import Config import cv2

config_path = 'configs/swin/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py' checkpoint = 'swin_base_models/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K_20210526_192340-593b0e13.pth' cfg = Config.fromfile(config_path) model = init_segmentor(cfg, checkpoint, device='cuda:0') img = cv2.imread('demo.jpg') result = inference_segmentor(model, img) print(result)

FreyWang commented 3 years ago

It's a bug,just remove the argument. use the script to transfer checkpoint from swin to mmseg manually.
https://github.com/open-mmlab/mmsegmentation/blob/master/tools/model_converters/swin2mmseg.py

MengzhangLI commented 3 years ago

Hi, it is a bug and we would fix it as soon as possible.

Best,

MengzhangLI commented 3 years ago

Hi, if you use the latest version of MMSeg, this 'pretrain_style' has been deprecated thus no bug would meet.

BuaaGray commented 3 years ago

I used a model from mmsegmentation, the bug still existed. mmcv 1.3.8 mmsegmentation 0.17.0 python 3.7.11

code:

config_file = '../configs/swin/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py'
checkpoint_file = '../checkpoints/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K_20210526_192340-593b0e13.pth' 
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')

error:

TypeError: SwinTransformer: __init__() got an unexpected keyword argument 'pretrain_style'
Junjun2016 commented 3 years ago

I used a model from mmsegmentation, the bug still existed. mmcv 1.3.8 mmsegmentation 0.17.0 python 3.7.11

code:

config_file = '../configs/swin/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py'
checkpoint_file = '../checkpoints/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K_20210526_192340-593b0e13.pth' 
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')

error:

TypeError: SwinTransformer: __init__() got an unexpected keyword argument 'pretrain_style'

pretrain_style has been deprecated in the latest version.

BuaaGray commented 3 years ago

I used a model from mmsegmentation, the bug still existed. mmcv 1.3.8 mmsegmentation 0.17.0 python 3.7.11 code:

config_file = '../configs/swin/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py'
checkpoint_file = '../checkpoints/upernet_swin_base_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K_20210526_192340-593b0e13.pth' 
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')

error:

TypeError: SwinTransformer: __init__() got an unexpected keyword argument 'pretrain_style'

pretrain_style has been deprecated in the latest version.

The latest version is 0.17.0, isn't it ?

Junjun2016 commented 3 years ago

https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/models/backbones/swin.py#L524

BuaaGray commented 3 years ago

I got it wrong before. It's better to remove pretrain_style in https://github.com/open-mmlab/mmsegmentation/blob/4d8229c141ae4f971b978a58c6b2861c59955fce/configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py#L15 and https://github.com/open-mmlab/mmsegmentation/blob/4d8229c141ae4f971b978a58c6b2861c59955fce/configs/_base_/models/upernet_swin.py#L27

Junjun2016 commented 3 years ago

We will fix it in this PR.