trancongman276 / yolov7-pose

Pose Detection based on YoloV7 deployed on ONNXRuntime
23 stars 4 forks source link

TensorRT inference error #6

Open oscar7eaglewatch opened 5 months ago

oscar7eaglewatch commented 5 months ago

Hi, Thanks for your work. I have tried to export your onnx model with TensorRT official API and it went well.

The original yolov7 exporting method to TensorRT (https://github.com/WongKinYiu/yolov7?tab=readme-ov-file#export) didn't work because your onnx model has -1 dimension as a batch size but the code (https://github.com/Linaom1214/tensorrt-python.git) requires the specific number of the batch size (1)

But when I tried to run the code (https://colab.research.google.com/github/WongKinYiu/yolov7/blob/main/tools/YOLOv7trt.ipynb#scrollTo=kRqqsjDcmyNj) of the yolov7 with export TRT file, it returns an error, it says that the (-1, 57) dimension can't be accepted.

Binding = namedtuple('Binding', ('name', 'dtype', 'shape', 'data', 'ptr'))
logger = trt.Logger(trt.Logger.INFO)
trt.init_libnvinfer_plugins(logger, namespace="")
with open(w, '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) # error at this line 
    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()
trancongman276 commented 3 months ago

Yes, in this case we need to re-export from PyTorch without using dynamic shape so that our input and output shape will not have (-1) shape. I am so busy with my current job rn so I will try my best to release the export code asap.