mmsegmentation: `mask2former` raised error: `class `Mask2FormerHead` in mmseg/models/decode_heads/mask2former_head.py: __init__() got an unexpected keyword argument 'in_channels'`

Hi, I was running mask2former using the base config mask2former_swin-b-in1k-384x384-pre_8xb2-160k_ade20k-640x640.py, and it rasied the following error:

TypeError: class `EncoderDecoder` in mmseg/models/segmentors/encoder_decoder.py: class `Mask2FormerHead` in mmseg/models/decode_heads/mask2former_head.py: __init__() got an unexpected keyword argument 'in_channels'

I looked into mask2former_head.py and suspected the root of the problem may lie in these lines: https://github.com/open-mmlab/mmsegmentation/blob/b600f7cb26829afa2c785af41755391626fbb446/mmseg/models/decode_heads/mask2former_head.py#L9-L13

As I hadn’t installed mmdetection, the alternatively imported BaseModule used as Mask2FormerHead from mmengine.model may not recognise in_channels. However after I installed mmdetection via mim install mmdet, I was experiencing the issue decribed in issue#2892, as mmengine version was automatically updated to 0.7.2 from 0.7.0 with mmdetection installed. I tried downgrading mmengine back to 0.7.0 and installed mmdetection by directly cloning its repo and manually installing via pip as instructed in here, but the latest version of mmdetection is incompatible with mmengine==0.7.0.

Environment

sys.platform: linux
Python: 3.8.16 | packaged by conda-forge | (default, Feb  1 2023, 16:01:55) [GCC 11.3.0]
CUDA available: True
numpy_random_seed: 2147483648
GPU 0: NVIDIA RTX A6000
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 11.6, V11.6.124
GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
PyTorch: 2.0.0
PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2022.1-Product Build 20220311 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.7
  - 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_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_37,code=compute_37
  - CuDNN 8.5
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -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 -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.0.0, USE_CUDA=ON, USE_CUDNN=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_ROCM=OFF, 

TorchVision: 0.15.0
OpenCV: 4.7.0
MMEngine: 0.7.0
MMSegmentation: 1.0.0rc6+ff95416

Thank you in advance!

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 4
  • Comments: 18 (1 by maintainers)

Most upvoted comments

Solved the problem by installing mmdetection without mim: git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection pip install -v -e .

@ff98li , I am not sure if this will solve your issue, but check the documentation here: https://github.com/open-mmlab/mmsegmentation/tree/b600f7cb26829afa2c785af41755391626fbb446/configs/mask2former

It is recommended to install mmdetection to run this model via: pip install “mmdet>=3.0.0rc4”

所以我不得不安装mmdetection,即使我正尝试使用mmsegmentation执行语言义分割。Mask2Former自述文件(此处)中对这样进行了说明。 有几种安装mmdetection的方法(参见此处的说明) 。但是,就我而言,通过 mim 安装 mmdetection 似乎会导致此错误。因此,我直接从 root 安装它。在此之后,一次切换似乎都正常。 I downloaded the MMdet compressed package, and put it in the same directory as MMseg. Both in the same conda environment, the following error will occur, class Mask2FormerHead in mmseg/models/decode_heads/mask2former_head.py: ‘ConfigDict’ object has no attribute ‘transformerlayers’ image image

通过在没有mmengine的情况下安装mmdetection 解决了这个问题: git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection pip install -v -e .

May I ask how to install, so that MMdetct and MMseg will not coincide

Same problem, when trying to use any mask2former model.

@ff98li , I am not sure if this will solve your issue, but check the documentation here: https://github.com/open-mmlab/mmsegmentation/tree/b600f7cb26829afa2c785af41755391626fbb446/configs/mask2former

It is recommended to install mmdetection to run this model via: pip install “mmdet>=3.0.0rc4”

Thank you for the reply @LHamnett! I indeed have tried installing mmdetection via pip install "mmdet>=3.0.0rc4, which raised the following error when running the model:

AssertionError: MMEngine==0.7.0 is used but incompatible. Please install mmengine>=0.7.1, <1.0.0.

while any mmengine version above 0.7.0 will raise the error in issue#2892. I have also tried “mmdet==3.0.0rc4” but it just brought me to issue#2619, and…since the current dev-3.x for mmdetection (which is the same as the main at this point) mentioned in the issue now requires mmengine>=0.7.1, it ultimately leads us back to issue#2892 again.