mmdeploy - ERROR - `mmdeploy.backend.tensorrt.onnx2tensorrt.onnx2tensorrt` with Call id: 1 failed. exit

See original GitHub issue

I was trying to convert Swin-T Mask R-CNN but getting following error:

[07/05/2022-13:55:25] [TRT] [I] No importer registered for op: TRTBatchedNMS. Attempting to import as plugin.
[07/05/2022-13:55:25] [TRT] [I] Searching for plugin: TRTBatchedNMS, plugin_version: 1, plugin_namespace: 
Process Process-3:
Traceback (most recent call last):
  File "/home/sort/miniconda3/envs/openmmlab/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/sort/miniconda3/envs/openmmlab/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/sort/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/sort/mmdeploy/mmdeploy/backend/tensorrt/onnx2tensorrt.py", line 79, in onnx2tensorrt
    from_onnx(
  File "/home/sort/mmdeploy/mmdeploy/backend/tensorrt/utils.py", line 113, in from_onnx
    raise RuntimeError(f'Failed to parse onnx, {error_msgs}')
RuntimeError: Failed to parse onnx, In node 2160 (importFallbackPluginImporter): UNSUPPORTED_NODE: Assertion failed: creator && "Plugin not found, are the plugin name, version, and namespace correct?"

2022-07-05 13:55:26,152 - mmdeploy - ERROR - `mmdeploy.backend.tensorrt.onnx2tensorrt.onnx2tensorrt` with Call id: 1 failed. exit.

I’m using following command:

python ./tools/deploy.py \
    'configs/mmdet/_base_/base_tensorrt-fp16_static-1050x1050.py' \
    '/home/sort/ved/sort/onion_l2/mask_rcnn_swin-t-p4-w7_fpn_fp16_ms-crop-3x_coco.py' \
    '/home/sort/ved/sort/onion_l2/mask_rcnn_swin/epoch_5.pth' \
    '/home/sort/ved/sort/onion_l2/data/val/images/10000000000001.0.jpg' \
    --test-img '/home/sort/ved/sort/onion_l2/data/val/images/1000000000012.0.jpg' \
    --work-dir '/home/sort/ved/sort/onion_l2/mmdeploy_out/' \
    --log-level DEBUG\
    --show \
    --device cuda:1

In file configs/mmdet/base/base_tensorrt-fp16_static-1050x1050.py I’m using 1056x1056 as dimensions.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
AllentDancommented, Jul 21, 2022

Hi, did you build MMDeploy from the source? Is there a file mmdeploy/lib/libmmdeploy_tensorrt_ops.so?

0reactions
anshkumarcommented, Jul 23, 2022

It worked. Here’s the final code:

from mmdeploy.backend.tensorrt import load_tensorrt_plugin
load_tensorrt_plugin()

import numpy as np
import os
import pycuda.driver as cuda
import pycuda.autoinit
import tensorrt as trt

from collections import OrderedDict, namedtuple
import torch
import cv2

device = 'cuda:0'
TRT_LOGGER = trt.Logger()

# Filenames of TensorRT plan file and input/output images.
engine_file = "/home/sort/ved/sort/apple_l2/mmdeploy_out/end2end.engine"
input_file = '/home/sort/ved/sort/apple_l2/data/val/images/970000000001.0.jpg'

# For torchvision models, input images are loaded in to a range of [0, 1] and
# normalized using mean = [0.485, 0.456, 0.406] and stddev = [0.229, 0.224, 0.225].
def preprocess(image):
    # Mean normalization
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    image_width = image.shape[1]
    image_height = image.shape[0]
    mean = np.array([0.485, 0.456, 0.406]).astype('float32')
    stddev = np.array([0.229, 0.224, 0.225]).astype('float32')
    image = (image.astype('float32') / float(255.0) - mean) / stddev
    image = np.moveaxis(image, 2, 0)
    image = np.expand_dims(image, axis=0)
    return image

def postprocess(bindings):
    results = bindings['dets'].data
    labels = bindings['labels'].data
    # masks = bindings['y.60'].data
    masks = bindings['masks'].data

    bboxes = results[0,:,:-1]
    scores = results[0,:,-1]
    labels = labels[0, :]
    masks = masks[0, :, :, :]

    masks = masks[scores > 0.3].cpu().detach().numpy()
    bboxes = bboxes[scores > 0.3].cpu().detach().numpy()
    labels = labels[scores > 0.3].cpu().detach().numpy()
    scores = scores[scores > 0.3].cpu().detach().numpy()
    return [bboxes, scores, labels, masks]

Binding = namedtuple('Binding', ('name', 'dtype', 'shape', 'data', 'ptr'))
logger = trt.Logger(trt.Logger.INFO)
with open(engine_file, 'rb') as f, trt.Runtime(logger) as runtime:
    model = runtime.deserialize_cuda_engine(f.read())
bindings = OrderedDict()
for index in range(model.num_bindings):
    name = model.get_binding_name(index)
    dtype = trt.nptype(model.get_binding_dtype(index))
    shape = tuple(model.get_binding_shape(index))
    data = torch.from_numpy(np.empty(shape, dtype=np.dtype(dtype))).to(device)
    bindings[name] = Binding(name, dtype, shape, data, int(data.data_ptr()))
binding_addrs = OrderedDict((n, d.ptr) for n, d in bindings.items())
context = model.create_execution_context()

image_cv = cv2.imread(input_file)
image = torch.from_numpy(preprocess(image_cv)).to(device)
binding_addrs['input'] = int(image.data_ptr())
stream = cuda.Stream()
context.execute_async_v2(bindings=list(binding_addrs.values()), stream_handle=stream.handle)
stream.synchronize()
bboxes, scores, labels, masks = postprocess(bindings)
Read more comments on GitHub >

github_iconTop Results From Across the Web

pytorch2onnx error on Jetson nano · Issue #641 - GitHub
' AssertionError: `mmdeploy.backend.tensorrt.onnx2tensorrt.onnx2tensorrt` with Call id: 1 failed.
Read more >
Tutorial 9: ONNX to TensorRT (Experimental)
Try the new MMDeploy to deploy your model. Tutorial 9: ONNX to TensorRT (Experimental). How to convert models from ONNX to TensorRT. Prerequisite....
Read more >
TensorRT 7.2.1 release notes - NVIDIA Documentation Center
Fixed a bug in the builder where networks with depthwise separable convolution layers whose output was also an FP32 output of the network...
Read more >
MMDeploy — Rust library // Lib.rs
Currently, mmdeploy-sys is built upon the pre-built package of mmdeploy so this repo only supports OnnxRuntime and TensorRT backends. Don't be disappoint, ...
Read more >
tools/deployment/onnx2tensorrt.py · tomofi/MMOCR at main
from mmcv.tensorrt import is_tensorrt_plugin_loaded, onnx2trt, save_trt_engine ... if isinstance(data[0]['img'], list) and len(data) > 1:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found