OpenGVLab / InternImage

[CVPR 2023 Highlight] InternImage: Exploring Large-Scale Vision Foundation Models with Deformable Convolutions
https://arxiv.org/abs/2211.05778
MIT License
2.52k stars 233 forks source link

TypeError: Mask2FormerHead: __init__() got an unexpected keyword argument 'num_things_classes' #219

Closed niuyixing closed 1 year ago

niuyixing commented 1 year ago

Traceback (most recent call last): File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(args) File "/home/ubuntu/InternImage-master/segmentation/mmseg_custom/models/decode_heads/mask2former_head.py", line 80, in init kwargs) TypeError: init() got an unexpected keyword argument 'num_things_classes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(*args) File "/home/ubuntu/InternImage-master/segmentation/mmseg_custom/models/segmentors/encoder_decoder_mask2former.py", line 39, in init self._init_decode_head(decode_head) File "/home/ubuntu/InternImage-master/segmentation/mmseg_custom/models/segmentors/encoder_decoder_mask2former.py", line 49, in _init_decode_head self.decode_head = builder.build_head(decode_head) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmseg/models/builder.py", line 30, in build_head return HEADS.build(cfg) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/utils/registry.py", line 215, in build return self.build_func(args, **kwargs, registry=self) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') TypeError: Mask2FormerHead: init() got an unexpected keyword argument 'num_things_classes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./train.py", line 248, in main() File "./train.py", line 204, in main test_cfg=cfg.get('test_cfg')) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmseg/models/builder.py", line 49, in build_segmentor cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg)) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/utils/registry.py", line 215, in build return self.build_func(*args, *kwargs, registry=self) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg raise type(e)(f'{obj_cls.name}: {e}') TypeError: EncoderDecoderMask2Former: Mask2FormerHead: init() got an unexpected keyword argument 'num_things_classes' ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 11959) of binary: /home/ubuntu/miniconda3/envs/internimage/bin/python Traceback (most recent call last): File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/torch/distributed/launch.py", line 193, in main() File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/torch/distributed/launch.py", line 189, in main launch(args) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/torch/distributed/launch.py", line 174, in launch run(args) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/torch/distributed/run.py", line 718, in run )(cmd_args) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/torch/distributed/launcher/api.py", line 131, in call return launch_agent(self._config, self._entrypoint, list(args)) File "/home/ubuntu/miniconda3/envs/internimage/lib/python3.7/site-packages/torch/distributed/launcher/api.py", line 247, in launch_agent failures=result.failures, torch.distributed.elastic.multiprocessing.errors.ChildFailedError:

DuinoDu commented 1 year ago

You can fix it by:

index 8fadaf0..719c547 100644
--- a/segmentation/mmseg_custom/models/decode_heads/mask2former_head.py
+++ b/segmentation/mmseg_custom/models/decode_heads/mask2former_head.py
@@ -29,6 +29,8 @@ class Mask2FormerHead(BaseDecodeHead):
         feat_channels (int): Number of channels for features.
         out_channels (int): Number of channels for output.
         num_classes (int): Number of classes.
+        num_things_classes (int): Number of things.
+        num_stuff_classes (int): Number of stuff.
         num_queries (int): Number of query in Transformer decoder.
         pixel_decoder (:obj:`mmcv.ConfigDict` | dict): Config for pixel
             decoder. Defaults to None.
@@ -58,6 +60,8 @@ class Mask2FormerHead(BaseDecodeHead):
                  feat_channels,
                  out_channels,
                  num_classes=80,
+                 num_things_classes=None,
+                 num_stuff_classes=None,
                  num_queries=100,
                  num_transformer_feat_level=3,
                  pixel_decoder=None,
niuyixing commented 1 year ago

Problem solved, thank you very much

lgwplay commented 4 months ago

Hello, when I was using mask2former, there was stuff and thing in the code, and num_thing, but no matter how I set it, the iou was basically zero. Please tell me how to solve this, there is no error.