参考:https://github.com/wang-xinyu/tensorrtx/tree/master/yolov5
在编译c++的tensorrt的时候报错,就用python版的测试。
// Install python-tensorrt, pycuda, etc.
// Ensure the yolov5s.engine and libmyplugins.so have been built
python yolov5_det_trt.py
// Another version of python script, which is using CUDA Python instead of pycuda.
python yolov5_det_trt_cuda_python.py
这里需要有yolov5s.engine
用官方的export导出的engine只能导出fp16的yolov5s.engine,不能进行量化。于是又找了量化工程。
参考:https://www.likecs.com/show-308293829.html
量化时候又报错:
# python convert_trt_quant.py
*** onnx to tensorrt begin ***
found all 230 images to calib.
Reading engine from file models_save/yolov5s_int8.trt
[05/05/2023-10:10:02] [TRT] [I] [MemUsageChange] Init CUDA: CPU +325, GPU +0, now: CPU 477, GPU 6922 (MiB)
[05/05/2023-10:10:02] [TRT] [I] Loaded engine size: 10 MiB
[05/05/2023-10:10:02] [TRT] [E] 1: [stdArchiveReader.cpp::StdArchiveReader::35] Error Code 1: Serialization (Serialization assertion safeVersionRead == safeSerializationVersion failed.Version tag does not match. Note: Current Version: 0, Serialized Engine Version: 96)
[05/05/2023-10:10:02] [TRT] [E] 4: [runtime.cpp::deserializeCudaEngine::50] Error Code 4: Internal Error (Engine deserialization failed.)
Traceback (most recent call last):
File "convert_trt_quant.py", line 104, in <module>
main()
File "convert_trt_quant.py", line 100, in main
assert engine_fixed, 'Broken engine_fixed'
AssertionError: Broken engine_fixed
查找原因是tensorrt版本不一致,我的是8.x,工程需要的是7.x,于是又重新拉取trt7.2的镜像。
docker pull nvcr.io/nvidia/pytorch:20.11-py3