在进行torch加速时,使用了torch-onnx-torch的思路,当前阶段已成功生成tensorrt engine,但是在使用tensor RT engine进行推理的过程中遇到了该报错:NotImplementedError: Converting dtype(‘float16’) to a ctypes type
推理实现过程参考的tensorRT github项目的example中的yolov3-https://github.com/NVIDIA/TensorRT/tree/release/8.6/samples/python/yolov3_onnx
报错是出现在common文件的HostDeviceMem函数中,意思是float16类型在ctype中没有定义,解决方式见TensorRT issue #3222:
I made a workaround :
1. Initialize np.ndarray from int16 ctypes point
2. use arr.dtype = np.float16 to change dtype inplace.
其意思就是既然ctype没有该类型,就在开辟内存时用int16类型来代替float16,因为他们占用的内存大小是一样的。