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

[MMSIG] Support the deployment of SparseInst on TensorRT #2541

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Boomerl
Copy link
Contributor

@Boomerl Boomerl commented Nov 10, 2023

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Support the deployment of real-time instance segmentation algorithm SparseInst on TensorRT backend.

Modification

Support the deployment of real-time instance segmentation algorithm SparseInst on TensorRT backend.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@Boomerl
Copy link
Contributor Author

Boomerl commented Nov 11, 2023

Because of the lack of sparseinst metafile, I didn't finish the regression test.

@mchaniotakis
Copy link

mchaniotakis commented Dec 5, 2023

Great work! Could we also include queryInst in this PR since they are very similar?

@Boomerl
Copy link
Contributor Author

Boomerl commented Dec 6, 2023

Great work! Could we also include queryInst in this PR since they are very similar?

OK, I will do it.

@RunningLeon

This comment was marked as resolved.

dets = torch.cat([bboxes, scores.unsqueeze(-1)], dim=-1)
masks = (pred_masks > self.mask_threshold).float()

return dets, labels, masks
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we post the evaluation results of trt model and check if it's aligned with pytorch model?


@FUNCTION_REWRITER.register_rewriter(
'projects.SparseInst.sparseinst.SparseInst.predict')
def sparseinst__predict(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when build trt engine, there's warning

Profile kMIN values are not self-consistent. /encoder/ppm/Resize_1: IResizeLayer requires that if input dimension is zero, output dimension must be zero too (axis = 3 input dimension = (+ (CEIL_DIV (+ width -800) 416) 1) output dimension = (+ (CEIL_DIV (+ width -32) 32) 1))
Condition '==' violated: 0 != 10. Instruction: CHECK_EQUAL 0 10.

This might lead to failure in some cases.
Running test.py failed after some iterations

Epoch(test) [  50/5000]    eta: 0:03:57  time: 0.0470  data_time: 0.0014  memory: 495  
12/15 02:59:38 - mmengine - INFO - Epoch(test) [ 100/5000]    eta: 0:03:35  time: 0.0413  data_time: 0.0013  memory: 506  
12/15 02:59:40 - mmengine - INFO - Epoch(test) [ 150/5000]    eta: 0:03:24  time: 0.0349  data_time: 0.0014  memory: 501  
12/15 02:59:42 - mmengine - INFO - Epoch(test) [ 200/5000]    eta: 0:03:16  time: 0.0358  data_time: 0.0014  memory: 501  
12/15 02:59:44 - mmengine - INFO - Epoch(test) [ 250/5000]    eta: 0:03:10  time: 0.0344  data_time: 0.0013  memory: 505  
12/15 02:59:46 - mmengine - INFO - Epoch(test) [ 300/5000]    eta: 0:03:07  time: 0.0371  data_time: 0.0013  memory: 501  
12/15 02:59:48 - mmengine - INFO - Epoch(test) [ 350/5000]    eta: 0:03:06  time: 0.0420  data_time: 0.0015  memory: 508  
12/15 02:59:50 - mmengine - INFO - Epoch(test) [ 400/5000]    eta: 0:03:03  time: 0.0340  data_time: 0.0013  memory: 501  
12/15 02:59:52 - mmengine - INFO - Epoch(test) [ 450/5000]    eta: 0:03:01  time: 0.0420  data_time: 0.0014  memory: 508  
12/15 02:59:54 - mmengine - INFO - Epoch(test) [ 500/5000]    eta: 0:02:59  time: 0.0390  data_time: 0.0014  memory: 502  
[12/15/2023-02:59:56] [TRT] [E] 7: [shapeMachine.cpp::executeContinuation::864] Error Code 7: Internal Error (/encoder/ppm/Resize_1: IResizeLayer requires that if input dimension is zero, output dimension must be zero too (axis = 3 input dimension = (+ (CEIL_DIV (+ width -800) 416) 1) output dimension = (+ (CEIL_DIV (+ width -32) 32) 1))
 Condition '==' violated: 0 != 12. Instruction: CHECK_EQUAL 0 12.)
Traceback (most recent call last):
  File "tools/test.py", line 159, in <module>
    main()
  File "tools/test.py", line 153, in main
    runner.test()
  File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/runner.py", line 1791, in test
    metrics = self.test_loop.run()  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/loops.py", line 435, in run
    self.run_iter(idx, data_batch)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/loops.py", line 454, in run_iter
    outputs = self.runner.model.test_step(data_batch)
  File "/usr/local/lib/python3.8/dist-packages/mmengine/model/base_model/base_model.py", line 145, in test_step
    return self._run_forward(data, mode='predict')  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/mmengine/model/base_model/base_model.py", line 340, in _run_forward
    results = self(**data, mode=mode)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/deploy/object_detection_model.py", line 296, in forward
    outputs = self.predict(inputs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/deploy/object_detection_model.py", line 313, in predict
    outputs = self.wrapper({self.input_name: imgs})
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/backend/tensorrt/wrapper.py", line 167, in forward
    shape = tuple(self.context.get_binding_shape(idx))
ValueError: __len__() should return >= 0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Boomerl From my experience, tensorrt have not supported nn.AdaptiveAvgPool2d which is used in here. This means sparseinst model can only accept static shape for tensorrt backends, which should use configs like configs/mmdet/instance-seg/instance-seg_tensorrt_static-800x1344.py.
You could include this note in docs like https://github.com/open-mmlab/mmdeploy/blob/main/docs/en/04-supported-codebases/mmdet.md#reminder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank u for the guidance, I will check it immediately.

@Boomerl
Copy link
Contributor Author

Boomerl commented Dec 30, 2023

When I use static deploy config to convert this model to trt, I met an error:
[TRT] [E] 4: [network.cpp::operator()::3088] Error Code 4: Internal Error (input: kMIN dimensions in profile 0 are [1,3,640,853] but input has static dimensions [1,3,576,864].)
How can I solve this error?

@RunningLeon
Copy link
Collaborator

When I use static deploy config to convert this model to trt, I met an error: [TRT] [E] 4: [network.cpp::operator()::3088] Error Code 4: Internal Error (input: kMIN dimensions in profile 0 are [1,3,640,853] but input has static dimensions [1,3,576,864].) How can I solve this error?

@Boomerl could you provide the full script you are running?

@Boomerl
Copy link
Contributor Author

Boomerl commented Jan 2, 2024

python3 tools/deploy.py \ configs/mmdet/instance-seg/instance-seg_sparseinst_tensorrt_static-640x640.py \ sparseinst/sparseinst_r50_iam_8xb8-ms-270k_coco.py \ sparseinst/sparseinst_r50_iam_8xb8-ms-270k_coco_20221111_181051-72c711cd.pth \ ./demo/resources/det.jpg \ --work-dir sparseinst/workdir/trt \ --device cuda \ --show \ --dump-info
This is the script I used to convert model.

@Boomerl
Copy link
Contributor Author

Boomerl commented Jan 2, 2024

I used the deploy config below:
base = [
'../base/base_instance-seg_static.py',
'../../base/backends/tensorrt.py'
]
onnx_config = dict(input_shape=None)
codebase_config = dict(post_processing=dict(export_postprocess_mask=True))
backend_config = dict(
common_config=dict(max_workspace_size=1 << 32),
model_inputs=[
dict(
input_shapes=dict(
input=dict(
min_shape=[1, 3, 640, 853],
opt_shape=[1, 3, 640, 853],
max_shape=[1, 3, 640, 853])))
])

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

Successfully merging this pull request may close these issues.

3 participants