mmdeploy: Tensor size mismatch

Hello, I am trying to convert a CascadeNet pth model into onnx and getting the same error:

root@e2e4892b0ebf:~/workspace/mmdeploy# python ./tools/deploy.py configs/mmdet/detection/detection_onnxruntime_dynamic.py cascade_mask_rcnn_hrnetv2p_w32_20e.py General.Model.table.detection.v2.pth demo.png [2022-05-19 16:21:23.549] [mmdeploy] [info] Register ‘DirectoryModel’ 2022-05-19 16:21:23,618 - mmdeploy - INFO - torch2onnx start. [2022-05-19 16:21:24.866] [mmdeploy] [info] Register ‘DirectoryModel’ /opt/conda/lib/python3.7/site-packages/mmdet/models/builder.py:53: UserWarning: train_cfg and test_cfg is deprecated, please specify them in model ‘please specify them in model’, UserWarning) load checkpoint from local path: General.Model.table.detection.v2.pth /opt/conda/lib/python3.7/site-packages/mmdet/datasets/utils.py:69: 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) 2022-05-19 16:21:32,430 - mmdeploy - WARNING - DeprecationWarning: get_onnx_config will be deprecated in the future. 2022-05-19:16:21:32,mmdeploy WARNING [utils.py:92] DeprecationWarning: get_onnx_config will be deprecated in the future. /root/workspace/mmdeploy/mmdeploy/core/optimizers/function_marker.py:158: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! ys_shape = tuple(int(s) for s in ys.shape) /opt/conda/lib/python3.7/site-packages/torch/nn/functional.py:3455: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details. “See the documentation of nn.Upsample for details.”.format(mode) /opt/conda/lib/python3.7/site-packages/mmdet/models/dense_heads/anchor_head.py:123: UserWarning: DeprecationWarning: anchor_generator is deprecated, please use “prior_generator” instead warnings.warn('DeprecationWarning: anchor_generator is deprecated, ’ /opt/conda/lib/python3.7/site-packages/mmdet/core/anchor/anchor_generator.py:333: UserWarning: grid_anchors would be deprecated soon. Please use grid_priors warnings.warn('grid_anchors would be deprecated soon. ’ /opt/conda/lib/python3.7/site-packages/mmdet/core/anchor/anchor_generator.py:370: UserWarning: single_level_grid_anchors would be deprecated soon. Please use single_level_grid_priors 'single_level_grid_anchors would be deprecated soon. ’ /root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/rpn_head.py:78: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! assert cls_score.size()[-2:] == bbox_pred.size()[-2:] /root/workspace/mmdeploy/mmdeploy/pytorch/functions/topk.py:28: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect. k = torch.tensor(k, device=input.device, dtype=torch.long) /root/workspace/mmdeploy/mmdeploy/pytorch/functions/topk.py:33: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! return ctx.origin_func(input, k, dim=dim, largest=largest, sorted=sorted) /opt/conda/lib/python3.7/site-packages/mmdet/core/bbox/coder/legacy_delta_xywh_bbox_coder.py:77: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs! assert pred_bboxes.size(0) == bboxes.size(0) 2022-05-19:16:21:35,root ERROR [utils.py:43] The size of tensor a (4) must match the size of tensor b (4432) at non-singleton dimension 2 Traceback (most recent call last): File “/root/workspace/mmdeploy/mmdeploy/utils/utils.py”, line 38, in target_wrapper result = target(*args, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/apis/pytorch2onnx.py”, line 113, in torch2onnx output_file=output_file) File “/root/workspace/mmdeploy/mmdeploy/apis/pytorch2onnx.py”, line 55, in torch2onnx_impl verbose=verbose) File “/opt/conda/lib/python3.7/site-packages/torch/onnx/init.py”, line 276, in export custom_opsets, enable_onnx_checker, use_external_data_format) File “/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py”, line 94, in export use_external_data_format=use_external_data_format) File “/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py”, line 698, in _export dynamic_axes=dynamic_axes) File “/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py”, line 456, in _model_to_graph use_new_jit_passes) File “/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py”, line 417, in _create_jit_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File “/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py”, line 377, in _trace_and_get_graph_from_model torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True) File “/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py”, line 1139, in _get_trace_graph outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs) File “/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 889, in _call_impl result = self.forward(*input, **kwargs) File “/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py”, line 130, in forward self._force_outplace, File “/opt/conda/lib/python3.7/site-packages/torch/jit/_trace.py”, line 116, in wrapper outs.append(self.inner(*trace_inputs)) File “/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 887, in _call_impl result = self._slow_forward(*input, **kwargs) File “/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py”, line 860, in _slow_forward result = self.forward(*input, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py”, line 371, in wrapper return self.func(self, *args, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base.py”, line 69, in base_detector__forward return __forward_impl(ctx, self, img, img_metas=img_metas, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/core/optimizers/function_marker.py”, line 261, in g rets = f(*args, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base.py”, line 28, in __forward_impl return self.simple_test(img, img_metas, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py”, line 371, in wrapper return self.func(self, *args, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/two_stage.py”, line 58, in two_stage_detector__simple_test proposals, _ = self.rpn_head.simple_test_rpn(x, img_metas) File “/opt/conda/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 “/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py”, line 371, in wrapper return self.func(self, *args, **kwargs) File “/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/rpn_head.py”, line 122, in rpn_head__get_bboxes max_shape=img_metas[0][‘img_shape’]) File “/opt/conda/lib/python3.7/site-packages/mmdet/core/bbox/coder/legacy_delta_xywh_bbox_coder.py”, line 79, in decode self.stds, max_shape, wh_ratio_clip) File “/opt/conda/lib/python3.7/site-packages/mmcv/utils/parrots_jit.py”, line 22, in wrapper_inner return func(*args, **kargs) File “/opt/conda/lib/python3.7/site-packages/mmdet/core/bbox/coder/legacy_delta_xywh_bbox_coder.py”, line 181, in legacy_delta2bbox denorm_deltas = deltas * stds + means RuntimeError: The size of tensor a (4) must match the size of tensor b (4432) at non-singleton dimension 2 2022-05-19 16:21:36,282 - mmdeploy - ERROR - torch2onnx failed.

Does anyone know what the problem might be? Thanks in advance!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21

Most upvoted comments

@RunningLeon Hi, Yes I have made it work using that as session options.

However I am encountering a new error now:

RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Add node. Name:‘Add_88’ Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/math/element_wise_ops.h:505 void onnxruntime::BroadcastIterator::Append(ptrdiff_t, ptrdiff_t) axis == 1 || axis == largest was false. Attempting to broadcast an axis by a dimension other than 1. 585 by 586

Does this mean there was an error converting?