TensorRT量化INT8模型报错记录及解决方案

基于C++将onnx 模型 转 TensorRT 模型(int8)

部分命令如下:

config->setFlag(nvinfer1::BuilderFlag::kINT8);
ICudaEngine* engine = builder->buildEngineWithConfig(*network, *config);

出现以下报错:

Error Code 4: Internal Error (Calibration failure occurred with no scaling factors detected. This could be due to no int8 calibrator or insufficient custom scales for network layers. Please see int8 sample to setup calibration correctly.)

并且返回的engine为nullptr。

测试显卡:1080Ti

原因:

查看了网上其他人反应的情况,在1080Ti显卡上会出现该问题,但在2080Ti上正常。https://github.com/NVIDIA/retinanet-examples/issues/129

由于没有在2080Ti上测试,不知其结果如何,但在3060(12G版本)上仍然有以上报错。

突然想起,可以采用trtexec进行模型转换。

于是采用以下命令

trtexec --onnx=test.onnx --saveEngine=test_int8.engine --int8

成功将将模型进行转化,没有任何报错。

猜你喜欢

转载自blog.csdn.net/chan1987818/article/details/132870272