在进行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,因为他们占用的内存大小是一样的。
解决torch-onnx-TensorRTfloat16类型转换问题
文章讲述了在将PyTorch模型转换为TensorRT并进行推理时遇到的NotImplementedError,涉及到float16到ctype类型的转换问题。作者通过将float16替换为int16作为临时解决方案,参考了TensorRTGitHub项目中的Yolov3示例。
1万+

被折叠的 条评论
为什么被折叠?



