mmdeploy
mmdeploy copied to clipboard
torch2onnx.py failed with KeyError: 'EncoderDecoder is not in the mmengine::model registry
Checklist
- [X] I have searched related issues but cannot get the expected help.
- [X] 2. I have read the FAQ documentation but cannot get the expected help.
- [X] 3. The bug has not been fixed in the latest version.
Describe the bug
Running torch2onnx.py
to convert segmentor model to onnx and got this bug
KeyError: 'EncoderDecoder is not in the mmengine::model registry. Please check whether the value of `EncoderDecoder` is correct or it was registered as expected.
If I add default_scope = 'mmseg'
in my model cfg following https://github.com/open-mmlab/mmsegmentation/issues/3395, I will get
raise KeyError(
KeyError: '`cfg` or `default_args` must contain the key "type", but got {}\nNone'
Note that I already source mmseg
to PYTHONPATH
Reproduction
Running python3 tools/torch2onnx.py
Environment
mmengine: '0.10.2'
mmseg: '1.2.2'
mmdeploy: '1.3.1'
Error traceback
Error 1:
01/10 21:58:07 - mmengine - INFO - torch2onnx:
model_cfg: /home/x/code/mmsegmentation_0_24_2/work_dirs/semanticE4_real_nov3_deegan_labels_10cls/semanticE4_real_nov3_deegan_labels_10cls.py
deploy_cfg: configs/mmseg/segmentation_onnxruntime-fp16_dynamic.py
01/10 21:58:08 - mmengine - WARNING - Failed to search registry with scope "mmseg" in the "Codebases" registry tree. As a workaround, the current "Codebases" registry in "mmdeploy" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmseg" is a correct scope, or whether the registry is initialized.
01/10 21:58:08 - mmengine - WARNING - Failed to search registry with scope "mmseg" in the "mmseg_tasks" registry tree. As a workaround, the current "mmseg_tasks" registry in "mmdeploy" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmseg" is a correct scope, or whether the registry is initialized.
01/10 21:58:08 - mmengine - WARNING - Failed to import `None.registry` make sure the registry.py exists in `None` package.
01/10 21:58:08 - mmengine - WARNING - Failed to search registry with scope "None" in the "model" registry tree. As a workaround, the current "model" registry in "mmengine" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "None" is a correct scope, or whether the registry is initialized.
Traceback (most recent call last):
File "/home/x/code/mmdeploy/tools/torch2onnx.py", line 86, in <module>
main()
File "/home/x/code/mmdeploy/tools/torch2onnx.py", line 48, in main
torch2onnx(
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
return self.call_function(func_name_, *args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
return self.call_function_local(func_name, *args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
return pipe_caller(*args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
ret = func(*args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 63, in torch2onnx
torch_mode = task_processor.build_pytorch_model(model_checkpoint)
File "/home/x/code/mmdeploy/mmdeploy/codebase/base/task.py", line 120, in build_pytorch_model
model = MODELS.build(model)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 100, in build_from_cfg
raise KeyError(
KeyError: 'EncoderDecoder is not in the mmengine::model registry. Please check whether the value of `EncoderDecoder` is correct or it was registered as expected. More details can be found at https://mmengine.readthedocs.io/en/latest/advanced_tutorials/config.html#import-the-custom-module'
Error 2:
Traceback (most recent call last):
File "/home/x/code/mmdeploy/tools/torch2onnx.py", line 86, in <module>
main()
File "/home/x/code/mmdeploy/tools/torch2onnx.py", line 48, in main
torch2onnx(
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
return self.call_function(func_name_, *args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
return self.call_function_local(func_name, *args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
return pipe_caller(*args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
ret = func(*args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 63, in torch2onnx
torch_model = task_processor.build_pytorch_model(model_checkpoint)
File "/home/x/code/mmdeploy/mmdeploy/codebase/base/task.py", line 120, in build_pytorch_model
model = MODELS.build(model)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
obj = obj_cls(**args) # type: ignore
File "/home/x/code/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 83, in __init__
super().__init__(
File "/home/x/code/mmsegmentation/mmseg/models/segmentors/base.py", line 30, in __init__
super().__init__(
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/model/base_model/base_model.py", line 78, in __init__
self.data_preprocessor = MODELS.build(data_preprocessor)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 72, in build_from_cfg
raise KeyError(
KeyError: '`cfg` or `default_args` must contain the key "type", but got {}\nNone'Traceback (most recent call last):
File "/home/x/code/mmdeploy/tools/torch2onnx.py", line 86, in <module>
main()
File "/home/x/code/mmdeploy/tools/torch2onnx.py", line 48, in main
torch2onnx(
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
return self.call_function(func_name_, *args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
return self.call_function_local(func_name, *args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
return pipe_caller(*args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
ret = func(*args, **kwargs)
File "/home/x/code/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 63, in torch2onnx
torch_model = task_processor.build_pytorch_model(model_checkpoint)
File "/home/x/code/mmdeploy/mmdeploy/codebase/base/task.py", line 120, in build_pytorch_model
model = MODELS.build(model)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg
obj = obj_cls(**args) # type: ignore
File "/home/x/code/mmsegmentation/mmseg/models/segmentors/encoder_decoder.py", line 83, in __init__
super().__init__(
File "/home/x/code/mmsegmentation/mmseg/models/segmentors/base.py", line 30, in __init__
super().__init__(
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/model/base_model/base_model.py", line 78, in __init__
self.data_preprocessor = MODELS.build(data_preprocessor)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/registry.py", line 570, in build
return self.build_func(cfg, *args, **kwargs, registry=self)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 232, in build_model_from_cfg
return build_from_cfg(cfg, registry, default_args)
File "/home/x/.conda/envs/mmseg0_24_2/lib/python3.9/site-packages/mmengine/registry/build_functions.py", line 72, in build_from_cfg
raise KeyError(
KeyError: '`cfg` or `default_args` must contain the key "type", but got {}\nNone'
same here, any progress?
same issue
same here, any progress?
No so I wrote my own code to convert the original segmenter model to onnx. That's fairly easy using the onnx documentation
could you show me your convert codes?