mmdeploy icon indicating copy to clipboard operation
mmdeploy copied to clipboard

Export texdet models to onnx failed

Open Phelan164 opened this issue 1 year ago • 3 comments

Thanks for your bug report. We appreciate it a lot.

Checklist

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

Describe the bug

(open-mmlab) tamnguyen ~/Desktop/working/src/mmocr [main] $ python tools/deployment/pytorch2onnx.py configs/textdet/maskrcnn/mask_rcnn_r50_fpn_160e_icdar2017.py ~/Downloads/mask_rcnn_r50_fpn_160e_icdar2017_20210218-c6ec3ebb.pth det ~/Desktop/the.png --output-file output.onnx --show tools/deployment/pytorch2onnx.py:337: UserWarning: DeprecationWarning: This tool will be deprecated in future. Welcome to use the unified model deployment toolbox MMDeploy: https://github.com/open-mmlab/mmdeploy warnings.warn(msg) load checkpoint from local path: /Users/tamnguyen/Downloads/mask_rcnn_r50_fpn_160e_icdar2017_20210218-c6ec3ebb.pth /Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/datasets/utils.py:70: UserWarning: "ImageToTensor" pipeline is replaced by "DefaultFormatBundle" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file. 'data pipeline in your config file.', UserWarning) /Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/onnx/symbolic.py:481: UserWarning: DeprecationWarning: This function will be deprecated in future. Welcome to use the unified model deployment toolbox MMDeploy: https://github.com/open-mmlab/mmdeploy warnings.warn(msg)

Traceback (most recent call last): File "tools/deployment/pytorch2onnx.py", line 370, in main() File "tools/deployment/pytorch2onnx.py", line 366, in main dynamic_export=args.dynamic_export) File "tools/deployment/pytorch2onnx.py", line 204, in pytorch2onnx dynamic_axes=dynamic_axes) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/onnx/init.py", line 208, in export custom_opsets, enable_onnx_checker, use_external_data_format) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/onnx/utils.py", line 92, in export use_external_data_format=use_external_data_format) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/onnx/utils.py", line 530, in _export fixed_batch_size=fixed_batch_size) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/onnx/utils.py", line 366, in _model_to_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/onnx/utils.py", line 319, in _trace_and_get_graph_from_model torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/jit/init.py", line 338, in _get_trace_graph outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/jit/init.py", line 426, in forward self._force_outplace, File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/jit/init.py", line 412, in wrapper outs.append(self.inner(*trace_inputs)) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 720, in _call_impl result = self._slow_forward(*input, **kwargs) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/torch/nn/modules/module.py", line 704, in _slow_forward result = self.forward(*input, **kwargs) File "/Users/tamnguyen/Desktop/working/src/mmocr/mmocr/models/textdet/detectors/ocr_mask_rcnn.py", line 64, in simple_test results = super().simple_test(img, img_metas, proposals, rescale) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/models/detectors/two_stage.py", line 179, in simple_test proposal_list = self.rpn_head.simple_test_rpn(x, img_metas) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/models/dense_heads/dense_test_mixins.py", line 130, in simple_test_rpn proposal_list = self.get_bboxes(*rpn_outs, img_metas=img_metas) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmcv/runner/fp16_utils.py", line 205, in new_func return old_func(*args, **kwargs) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/models/dense_heads/base_dense_head.py", line 105, in get_bboxes **kwargs) File "/Users/tamnguyen/opt/anaconda3/envs/open-mmlab/lib/python3.7/site-packages/mmdet/models/dense_heads/rpn_head.py", line 141, in _get_bboxes_single img_shape = img_meta['img_shape'] TypeError: list indices must be integers or slices, not str

Reproduction

  1. What command or script did you run?
A placeholder for the command.
  1. Did you make any modifications on the code or config? Did you understand what you have modified? I think the img_meta type already changed to list then now it is not dict anymore

Environment

  1. Please run python tools/check_env.py to collect necessary environment information and paste it here.
  2. 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.)

Error traceback

If applicable, paste the error trackback here.

A placeholder for trackback.

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!

Phelan164 avatar Jul 26 '22 03:07 Phelan164

Hi, @Phelan164 please refer to the supported model list. Mask RCNN for text detection is not in the list.

AllentDan avatar Jul 26 '22 03:07 AllentDan

btw, other modesl such as maskrnn, dbnet also have the same problem

Phelan164 avatar Jul 26 '22 03:07 Phelan164

Could you run python tools/check_env.py to collect necessary environment information and paste it here?

AllentDan avatar Jul 26 '22 04:07 AllentDan

Closing it for no activity for a long time, feel free to reopen it if it is still an issue for you.

AllentDan avatar Sep 29 '22 09:09 AllentDan