grimoire/mmdetection-to-tensorrt

DCNv2 support

anshkumar opened this issue · 2 comments

Trying to convert Faster RCNN R-50 DCNv2 to tensorRT, but I'm getting following error:

[TensorRT] ERROR: Parameter check failed at: engine.cpp::setBindingDimensions::948, condition: profileMaxDims.d[i] >= dimensions.d[i]
[TensorRT] ERROR: Parameter check failed at: engine.cpp::resolveSlots::1092, condition: allInputDimensionsSpecified(routine)
Traceback (most recent call last):
  File "infer_rt.py", line 59, in <module>
    results = model(image_batch)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/root/space/torch2trt_dynamic/torch2trt_dynamic/torch2trt_dynamic.py", line 458, in forward
    shape = tuple(self.context.get_binding_shape(idx))
ValueError: __len__() should return >= 0

Here is my code:

import mmcv
import os
import time
import numpy as np
import cv2
from mmdet2trt import mmdet2trt
from mmdet2trt.apis import inference_detector, init_detector
import torch
from mmdet.datasets.pipelines import Compose

config_file = '/models/faster_rcnn_r50_fpn_mdconv_c3-c5_group4_1x_coco.py'
checkpoint_file = '/models/output.trt'

model = init_detector(checkpoint_file)

def preprocess(img, cfg):
    if isinstance(cfg, str):
        cfg = mmcv.Config.fromfile(cfg)
    data = dict(img=img)
    cfg = cfg.copy()
    cfg.data.test.pipeline[0].type = 'LoadImageFromWebcam'
    test_pipeline = cfg.data.test.pipeline
    test_pipeline = Compose(test_pipeline)
    data = test_pipeline(data)
    return data['img'][0]._data

def draw_label(image, point, label, font=cv2.FONT_HERSHEY_SIMPLEX,
               font_scale=0.5, thickness=2):
    size = cv2.getTextSize(label, font, font_scale, thickness)[0]
    x, y = point
    cv2.rectangle(image, (x, y - size[1]),
                  (x + size[0], y), (255, 0, 0), cv2.FILLED)
    cv2.putText(image, label, point, font, font_scale,
                (255, 255, 255), thickness)

IMAGE_PATH = "/models/dataset/sort_potato_l2/val/images"
image_batch = []
for img in os.listdir(IMAGE_PATH):
    if img.endswith("jpg"):
        image = os.path.join(IMAGE_PATH, img)
        image = cv2.imread(image)
        image = preprocess(image, config_file)
        image_batch.append(image)
    if len(image_batch) == 4:
        tic = time.time()
        image_batch = torch.stack(image_batch, axis = 0).cuda()
        results = model(image_batch)
        print("FPS: ", 1/(time.time()-tic))
        image_batch = []

Hi
According to the log, the shape of the input tensor is larger than what you set in opt_shape_param. Please make sure all input tensor are inside the shape range.

@grimoire I changed the input tensor according my input image using the cli as follows:

sudo docker run --gpus all -it --rm -v /home/deploy/ved/:/models/ mmdet2trt_docker:v1.0 --fp16 True --max-workspace-gb 11 --min-scale 1 3 750 750 --opt-scale 4 3 750 750 --max-scale 4 3 750 750 /models/faster_rcnn_r50_fpn_mdconv_c3-c5_group4_1x_coco.py /models/faster_rcnn_r50_fpn_mdconv_c3-c5_group4/epoch_32.pth /models/output.trt

Then I'm getting following error:

Cuda error in file src/implicit_gemm.cu at line 1169: an illegal memory access was encountered
[TensorRT] ERROR: ../rtSafe/cuda/caskConvolutionRunner.cpp (233) - Cuda Error in allocateContextResources: 700 (an illegal memory access was encountered)
[TensorRT] ERROR: FAILED_EXECUTION: std::exception
FPS:  5.709806569477211
[TensorRT] ERROR: ../rtSafe/safeContext.cpp (133) - Cudnn Error in configure: 7 (CUDNN_STATUS_MAPPING_ERROR)
[TensorRT] ERROR: FAILED_EXECUTION: std::exception