Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError: max_shape should be tensor of (h,w) for onnx for FCOS model #679

Closed
sarmientoj24 opened this issue Jun 29, 2022 · 1 comment
Assignees

Comments

@sarmientoj24
Copy link

I ran this command to convert the model I trained

python mmdeploy/tools/deploy.py mmdeploy/configs/mmdet/detection/detection_onnxruntime_static.py configs/cfg.py checkpoint.pt 000544.jpg --show --log-level INFO --dump-info

Error

Process Process-2:
Traceback (most recent call last):
  File "useranaconda3/envs/yl/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "useranaconda3/envs/yl/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 105, in __call__
    ret = func(*args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 97, in torch2onnx
    keep_initializers_as_inputs=keep_initializers_as_inputs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 354, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 324, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 273, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 105, in __call__
    ret = func(*args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/onnx/export.py", line 131, in export
    verbose=verbose)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/onnx/__init__.py", line 320, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/onnx/utils.py", line 111, in export
    custom_opsets=custom_opsets, use_external_data_format=use_external_data_format)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/onnx/utils.py", line 729, in _export
    dynamic_axes=dynamic_axes)
  File "usermmdetection/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 371, in wrapper
    return self.func(self, *args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/onnx/optimizer.py", line 10, in model_to_graph__custom_optimizer
    graph, params_dict, torch_out = ctx.origin_func(*args, **kwargs)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/onnx/utils.py", line 493, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/onnx/utils.py", line 437, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/onnx/utils.py", line 388, in _trace_and_get_graph_from_model
    torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/jit/_trace.py", line 1166, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/jit/_trace.py", line 132, in forward
    self._force_outplace,
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/jit/_trace.py", line 118, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "useranaconda3/envs/yl/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1090, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 371, in wrapper
    return self.func(self, *args, **kwargs)
  File "usermmdetection/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 "usermmdetection/mmdeploy/mmdeploy/core/optimizers/function_marker.py", line 261, in g
    rets = f(*args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base.py", line 28, in __forward_impl
    return self.simple_test(img, img_metas, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 371, in wrapper
    return self.func(self, *args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/single_stage.py", line 28, in single_stage_detector__simple_test
    return self.bbox_head.simple_test(feat, img_metas, **kwargs)
  File "usermmdetection/mmdetection/mmdet/models/dense_heads/base_dense_head.py", line 360, in simple_test
    return self.simple_test_bboxes(feats, img_metas, rescale=rescale)
  File "usermmdetection/mmdetection/mmdet/models/dense_heads/dense_test_mixins.py", line 38, in simple_test_bboxes
    *outs, img_metas=img_metas, rescale=rescale)
  File "usermmdetection/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 371, in wrapper
    return self.func(self, *args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py", line 149, in base_dense_head__get_bbox
    batch_priors, batch_mlvl_bboxes_pred, max_shape=img_shape)
  File "usermmdetection/mmdetection/mmdet/core/bbox/coder/distance_point_bbox_coder.py", line 63, in decode
    return distance2bbox(points, pred_bboxes, max_shape)
  File "usermmdetection/mmdetection/mmdet/core/bbox/transforms.py", line 170, in distance2bbox
    x1, y1, x2, y2 = dynamic_clip_for_onnx(x1, y1, x2, y2, max_shape)
  File "usermmdetection/mmdetection/mmdet/core/export/onnx_helper.py", line 24, in dynamic_clip_for_onnx
    torch.Tensor), '`max_shape` should be tensor of (h,w) for onnx'
AssertionError: `max_shape` should be tensor of (h,w) for onnx
Traceback (most recent call last):
  File "mmdeploy/tools/deploy.py", line 366, in <module>
    main()
  File "mmdeploy/tools/deploy.py", line 136, in main
    device=args.device)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 354, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 322, in call_function
    return self.get_result_sync(call_id)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 303, in get_result_sync
    ret = self.get_caller(func_name).pop_mp_output(call_id)
  File "usermmdetection/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 80, in pop_mp_output
    f'`{self._func_name}` with Call id: {call_id} failed.'
AssertionError: `mmdeploy.apis.pytorch2onnx.torch2onnx` with Call id: 0 failed.
@hanrui1sensetime
Copy link
Collaborator

Now you can use detection_onnxruntime_dynamic.py instead of detection_onnxruntime_static.py. And later we will fix the detection_onnxruntime_dynamic.py`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants