TensorRT: 8.6.1.6 CUDA: 12.6 CUDNN: 8.9.0
在开始之前,需要修改 include/yololayer.h 文件中的相关参数,确保它们与您的训练过程配置一致:
static constexpr int MAX_OUTPUT_BBOX_COUNT = 1000;
static constexpr int CLASS_NUM = 80; // 类别数
static constexpr int INPUT_H = 640; // yolov5-lite的输入高度,必须能被32整除
static constexpr int INPUT_W = 640; // yolov5-lite的输入宽度,必须能被32整除
static constexpr int DEVICE = 0;
static constexpr float NMS_THRESH = 0.4;
static constexpr float CONF_THRESH = 0.45;
static constexpr int BATCH_SIZE = 1;
const char* INPUT_BLOB_NAME = "data";
const char* OUTPUT_BLOB_NAME = "prob";此过程必须在yolov5-lite文件夹中完成:
python gen_wts.py -w v5lite-s.pt -o v5lite-s.wts
python gen_wts.py -w v5lite-e.pt -o v5lite-e.wts
python gen_wts.py -w v5lite-g.pt -o v5lite-g.wtsa. 首先在include文件夹中找到yololayer.h文件,将CLASS_NUM改为您的数据集对应的类别数,这一步非常重要,否则会报错!
b. 在终端中执行以下命令:
mkdir build
cd build
cmake ..
make./v5lite -s ../v5lite-s.wts v5lite-s.engine s
./v5lite -s ../v5lite-g.wts v5lite-g.engine g
./v5lite -s ../v5lite-e.wts v5lite-e.engine e
./v5lite -s ../v5lite-c.wts v5lite-c.engine c(samples是您存放图片的文件夹):
./v5lite -d v5lite-s.engine ../samples您也可以使用yolov5-lite-trt.py进行推理。
-
获取训练集的图片,数量建议1000张左右
-
将图片放入指定的校准数据文件夹中(例如:
tensorrtx-int8calib-data/coco_calib) -
修改v5lite.cpp中的宏定义:
将:
// #define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32 // #define USE_INT8 // set USE_INT8 or USE_FP16 or USE_FP32
改为:
// #define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32 #define USE_INT8 // set USE_INT8 or USE_FP16 or USE_FP32
-
更新代码中的数据路径,指向您的校准图像文件夹
-
重新编译并生成engine进行推理(重复步骤2)
- 实际测试中发现Python调用engine的推理效果可能更好