Skip to content

Pointrend cannot be converted to tensorrt #827

@Happyrealone

Description

@Happyrealone

In the official documentation's support list, pointrend in mmsegmentation is supported for conversion to tensorrt, but there is a problem

python mmdeploy/tools/deploy.py mmdeploy/configs/mmseg/segmentation_tensorrt_dynamic-512x
1024-2048x2048.py Project/mmsegmentation/configs/point_rend/pointrend_r50_512x1024_80k_cityscapes.py pointrend_r50_512x1
024_80k_cityscapes_20200711_015821-bb1ff523.pth input.jpg --work-dir test
[2022-07-28 02:24:08.199] [mmdeploy] [info] [model.cpp:95] Register 'DirectoryModel'
[2022-07-28 02:24:09.955] [mmdeploy] [info] [model.cpp:95] Register 'DirectoryModel'
[2022-07-28 02:24:11.776] [mmdeploy] [info] [model.cpp:95] Register 'DirectoryModel'
2022-07-28 02:24:11,781 - mmdeploy - INFO - Start pipeline mmdeploy.apis.pytorch2onnx.torch2onnx in subprocess
/opt/conda/lib/python3.8/site-packages/mmseg/models/losses/cross_entropy_loss.py:235: UserWarning: Default ``avg_non_ignore`` is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch official cross_entropy, set ``avg_non_ignore=True``.
  warnings.warn(
load checkpoint from local path: pointrend_r50_512x1024_80k_cityscapes_20200711_015821-bb1ff523.pth
2022-07-28 02:24:12,927 - mmdeploy - WARNING - DeprecationWarning: get_onnx_config will be deprecated in the future.
2022-07-28 02:24:12,928 - mmdeploy - INFO - Export PyTorch model to ONNX: test/end2end.onnx.
2022-07-28 02:24:12,958 - mmdeploy - WARNING - Can not find torch._C._jit_pass_onnx_deduplicate_initializers, function rewrite will not be applied
/opt/conda/lib/python3.8/site-packages/mmseg/ops/wrappers.py:48: 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!
  size = [int(t * self.scale_factor) for t in x.shape[-2:]]
/root/workspace/mmdeploy/mmdeploy/pytorch/functions/topk.py:56: 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!
  if k > size:
/opt/conda/lib/python3.8/site-packages/mmseg/models/decode_heads/point_head.py:352: 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!
  num_points = min(height * width, num_points)
2022-07-28 02:24:14,099 - mmdeploy - WARNING - Maximum K of TopK in TensorRT is 3840, but given 8196. Note that k will be set to 3840.
Process Process-2:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/opt/conda/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 92, in torch2onnx
    export(
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/onnx/export.py", line 122, in export
    torch.onnx.export(
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/__init__.py", line 316, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 107, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 724, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/root/workspace/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 "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 493, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 437, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/opt/conda/lib/python3.8/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 "/opt/conda/lib/python3.8/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 "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 118, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1090, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmseg/models/segmentors/base.py", line 41, in base_segmentor__forward
    return self.simple_test(img, img_metas, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmseg/models/segmentors/encoder_decoder.py", line 25, in encoder_decoder__simple_test
    seg_logit = self.encode_decode(img, img_meta)
  File "/opt/conda/lib/python3.8/site-packages/mmseg/models/segmentors/cascade_encoder_decoder.py", line 57, in encode_decode
    out = self.decode_head[i].forward_test(x, out, img_metas,
  File "/opt/conda/lib/python3.8/site-packages/mmseg/models/decode_heads/point_head.py", line 237, in forward_test
    point_indices, points = self.get_points_test(
  File "/opt/conda/lib/python3.8/site-packages/mmseg/models/decode_heads/point_head.py", line 360, in get_points_test
    point_coords[:, :, 0] = w_step / 2.0 + (point_indices %
  File "/root/workspace/mmdeploy/mmdeploy/core/rewriters/rewriter_utils.py", line 379, in wrapper
    return self.func(self, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/pytorch/functions/tensor_setitem.py", line 26, in tensor__setitem__default
    return ctx.origin_func(self, key, value)
RuntimeError: The expanded size of the tensor (8196) must match the existing size (3840) at non-singleton dimension 1.  Target sizes: [1, 8196].  Tensor sizes: [3840]
2022-07-28 02:24:14,419 - mmdeploy - ERROR - `mmdeploy.apis.pytorch2onnx.torch2onnx` with Call id: 0 failed. exit.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions