dynamic|static X fp16|fp32 Tensrort Engine Inference Using Yolov5 Model

experiment condition: python==3.8.0 torch==2.1.0 ultralytics:77fc5ccf02ac0fdf9e7bb1eeb003e9bf3e719702 tensorrt==8.6.1.post1 dynamic static fp16 dynamic_fp16 static_fp16 fp32 static_fp32 另外训练时候的padding模式决定了模型inference时候的前处理形式,进而导致不同的运行时间,在letterbox函数进行 前处理的时候,以下代码都保证了模型的正确输出,但并不能保证此种调用方式是效率最佳的方式,还需要继续优化。 Dynamic_Fp16 inshape from get_binding_shape(0): (1, 3, -1, 640) outshape from get_binding_shape(1): (0) dynamic inshape: (1, 3, 640, 640) dynamicoutshape: (1, 7, 8400) trt_run.py:71: DeprecationWarning: Use set_input_shape instead. context.set_binding_shape(0, image.shape) trt_run.py:72: DeprecationWarning: Use set_input_shape instead. context.set_binding_shape(1, output.shape) [11/23/2023-23:19:05] [TRT] [E] 3: [executionContext.cpp::setBindingDimensions::1511] Error Code 3: API Usage Error (Parameter check failed at: runtime/api/executionContext.cpp::setBindingDimensions::1511, condition: mEngine.bindingIsInput(bindingIndex) ) set binding time: 0....

November 23, 2023 · 6 min · 1169 words · 🤽奔波鲅

Pytorch Onnx Tensorrt Transfer Methods, Advantages and Disadvantages Using Yolov5 Model

experiment condition: python==3.8.0 torch==2.1.0 ultralytics:77fc5ccf02ac0fdf9e7bb1eeb003e9bf3e719702 tensorrt==8.6.1.post1 一. pt转onnx 1.ultralytics工程自带的model.export功能 1.1 dynamic input and output 1.2 static input and output 2.torch自带的export功能 2.1 dynamic input and output 2.2 static input and output 二. onnx转tensorrt-engine 1.torch自带的export功能 三.使用ultralytic中的model.export直接pt转为engine 主要是以yolov5模型为例,记录该模型在不同转换工具下的转换方法、转换后模型调用方式、模型调用效率测试。 想要从pt文件转换为tensorrt的engine类型,有两种大路径,其中又可以分化: pt–>onnx–>engine using torch.export to realize pt–>onnx convertion torch.onnx.export(model, input_tensor, model_name, opset_version=11, input_names=['input'], output_names=['output0','output1','output2','output3'], dynamic_axes=None) using model.export in ultralytics to realize pt–>onnx convertion path = model.export(format="onnx", dynamic=True, simplify=True, half=True) pt–>engine using model.export in ultralytics to directly realize pt–>engine convertion model....

November 23, 2023 · 6 min · 1099 words · lvsolo