onnx模型转为trt模型

命令

想要加速推理速度,一定要用半精度/混合精度,即(-d 16)

onnx2trt decode.onnx -o decode.trt -b 1 -d 16

错误

把onnx模型转TensorRT模型的trt模型时,报错

[2022-10-28 05:53:29 WARNING] /home/chen/CodeBase/onnx-tensorrt/onnx2trt_utils.cpp:362: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.

解决

安装onnx-simplifier

pip install onnx-simplifier

假设你想转换的模型是decode.onnx,先用如下命令转成decode_simple.onnx

python -m onnxsim decode.onnx decode_simple.onnx

接下来将新生成的decode_simple.onnx模型正常转换为trt模型即可

onnx2trt decode_simple.onnx -o decode.trt -b 1 -d 16

补充

执行命令python -m onnxsim decode.onnx decode_simple.onnx过程中我提示了这个错误

ModuleNotFoundError: No module named 'onnxruntime'

安装一下就好了

pip install onnxruntime

猜你喜欢

转载自blog.csdn.net/weixin_42156097/article/details/127571229