SwinTransformer / Swin-Transformer-Semantic-Segmentation

This is an official implementation for "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows" on Semantic Segmentation.
https://arxiv.org/abs/2103.14030
Apache License 2.0
1.17k stars 222 forks source link

Tried to run demo, got unexpected keyword argument 'pretrain_style' #44

Open SHMCU opened 3 years ago

SHMCU commented 3 years ago

Thanks for your error report and we appreciate it a lot.

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. The bug has not been fixed in the latest version.

Describe the bug A clear and concise description of what the bug is.

Reproduction

  1. What command or script did you run?

    (swin_transformer) [user@node001 mmsegmentation-master]$ python ./demo/image_demo.py /datasets/ADE20K/ADEChallengeData2016/images/validation/ADE_val_00000001.jpg ./configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py ./pretrained/upernet_swin_tiny_patch4_window7_512x512.pth
  2. Did you make any modifications on the code or config? Did you understand what you have modified? No modifications.

  3. What dataset did you use? ADE20K

Environment

  1. Please run python mmseg/utils/collect_env.py to collect necessary environment infomation and paste it here.
python collect_env.py 
fatal: Not a git repository (or any parent up to mount point /data2)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
sys.platform: linux
Python: 3.7.11 (default, Jul 27 2021, 14:32:16) [GCC 7.5.0]
CUDA available: True
GPU 0,1,2,3,4,5,6,7: Tesla V100-SXM2-32GB
CUDA_HOME: /cm/shared/apps/cuda10.1/toolkit/10.0.130
GCC: gcc (GCC) 6.3.0
PyTorch: 1.6.0
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) oneAPI Math Kernel Library Version 2021.3-Product Build 20210617 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v1.5.0 (Git Hash e2ac1fac44c5078ca927cb9b90e1b3066a0b2ed0)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 10.2
  - 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;arch=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.5
  - Magma 2.5.2
  - Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_VULKAN_WRAPPER -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF, 

TorchVision: 0.7.0
OpenCV: 4.5.3
MMCV: 1.3.9
MMCV Compiler: GCC 7.3
MMCV CUDA Compiler: 10.2
MMSegmentation: 0.16.0+
  1. You may add addition that may be helpful for locating the problem, such as
    • How you installed PyTorch [e.g., pip, conda, source]
    • Other environment variables that may be related (such as $PATH, $LD_LIBRARY_PATH, $PYTHONPATH, etc.)
      conda create -n swin_transformer python=3.7 -y
      conda activate swin_transformer
      conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2 -c pytorch

      Error traceback

If applicable, paste the error trackback here.

python ./demo/image_demo.py /datasets/ADE20K/ADEChallengeData2016/images/validation/ADE_val_00000001.jpg ./configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py ./pretrained/upernet_swin_tiny_patch4_window7_512x512.pth
Traceback (most recent call last):
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/utils/registry.py", line 51, in build_from_cfg
    return obj_cls(**args)
TypeError: __init__() got an unexpected keyword argument 'pretrain_style'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/utils/registry.py", line 51, in build_from_cfg
    return obj_cls(**args)
  File "/data2/userdata/user/workSpace/Swin-Transformer-Seg/mmsegmentation-master/mmseg/models/segmentors/encoder_decoder.py", line 36, in __init__
    self.backbone = builder.build_backbone(backbone)
  File "/data2/userdata/user/workSpace/Swin-Transformer-Seg/mmsegmentation-master/mmseg/models/builder.py", line 20, in build_backbone
    return BACKBONES.build(cfg)
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/utils/registry.py", line 210, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 26, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/utils/registry.py", line 54, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
TypeError: SwinTransformer: __init__() got an unexpected keyword argument 'pretrain_style'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./demo/image_demo.py", line 40, in <module>
    main()
  File "./demo/image_demo.py", line 27, in main
    model = init_segmentor(args.config, args.checkpoint, device=args.device)
  File "/data2/userdata/user/workSpace/Swin-Transformer-Seg/mmsegmentation-master/mmseg/apis/inference.py", line 32, in init_segmentor
    model = build_segmentor(config.model, test_cfg=config.get('test_cfg'))
  File "/data2/userdata/user/workSpace/Swin-Transformer-Seg/mmsegmentation-master/mmseg/models/builder.py", line 49, in build_segmentor
    cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg))
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/utils/registry.py", line 210, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 26, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/home/user/work/anaconda3/envs/swin_transformer/lib/python3.7/site-packages/mmcv/utils/registry.py", line 54, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
TypeError: EncoderDecoder: SwinTransformer: __init__() got an unexpected keyword argument 'pretrain_style'

Bug fix

If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!

hardyho commented 3 years ago

Same bug occur when trying to run python tools/get_flops.py configs/swin/upernet_swin_tiny_patch4_window7_512x512_160k_ade20k_pretrain_224x224_1K.py to calculate GFLOPs. Seems like it's a bug caused by recent commit https://github.com/open-mmlab/mmsegmentation/commit/c11da07e182e5ffbda1d3ff35f39da044a1c38c9#diff-220e913fe1515768f468297de42055bae53515200c833bd4e85f74e3d5a0dddf

justinnee commented 3 years ago

same bug