Hi, thanks for your awesome code share!
I test this repo on my Ubuntu 18 Linux with CUDA V11.2.152, TensorRT-8.0.0.3 and cudnn8.2.0.
I tested yolox_s model in FP32、FP16 and INT8 mode, but in INT8 mode, the network output has no results.
FP16 test code is below:
static void test_fp16(Yolo::Type type){
TRT::set_device(0);
INFO("===================== test %s fp16 ==================================", Yolo::type_name(type));
const char* name = nullptr;
if(type == Yolo::Type::V5){
name = "yolov5m";
}else if(type == Yolo::Type::X){
name = "yolox_s";
}
if(not requires(name))
return;
string onnx_file = iLogger::format("%s.onnx", name);
string model_file = iLogger::format("%s.fp16.trtmodel", name);
int test_batch_size = 1; // 当你需要修改batch大于1时,请注意你的模型是否修改(看readme.md代码修改部分),否则会有错误
// 动态batch和静态batch,如果你想要弄清楚,请打开http://www.zifuture.com:8090/
// 找到右边的二维码,扫码加好友后进群交流(免费哈,就是技术人员一起沟通)
if(not iLogger::exists(model_file)){
TRT::compile(
TRT::TRTMode_FP16, // 编译方式有,FP32、FP16、INT8
{}, // onnx时无效,caffe的输出节点标记
test_batch_size, // 指定编译的batch size
onnx_file, // 需要编译的onnx文件
model_file, // 储存的模型文件
{}, // 指定需要重定义的输入shape,这里可以对onnx的输入shape进行重定义
false // 是否采用动态batch维度,true采用,false不采用,使用静态固定的batch size
);
}
forward_engine(model_file, type);
}
Below is the output of the log:
[2021-09-01 19:38:45][info][app_yolo.cpp:240]:===================== test YoloX fp32 ==================================
[2021-09-01 19:38:45][info][trt_builder.cpp:473]:Compile FP32 Onnx Model 'yolox_s.onnx'.
[2021-09-01 19:38:45][info][trt_builder.cpp:602]:Input shape is 1 x 3 x 640 x 640
[2021-09-01 19:38:45][info][trt_builder.cpp:603]:Set max batch size = 1
[2021-09-01 19:38:45][info][trt_builder.cpp:604]:Set max workspace size = 1024.00 MB
[2021-09-01 19:38:45][info][trt_builder.cpp:605]:Dynamic batch dimension is false
[2021-09-01 19:38:45][info][trt_builder.cpp:608]:Network has 1 inputs:
[2021-09-01 19:38:45][info][trt_builder.cpp:614]: 0.[images] shape is 1 x 3 x 640 x 640
[2021-09-01 19:38:45][info][trt_builder.cpp:620]:Network has 1 outputs:
[2021-09-01 19:38:45][info][trt_builder.cpp:625]: 0.[output] shape is 1 x 8400 x 85
[2021-09-01 19:38:45][info][trt_builder.cpp:670]:Building engine...
[2021-09-01 19:38:45][warn][trt_builder.cpp:33]:NVInfer WARNING: Convolution + generic activation fusion is disable due to incompatible driver or nvrtc
[2021-09-01 19:38:46][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:38:46][warn][trt_builder.cpp:33]:NVInfer WARNING: Detected invalid timing cache, setup a local cache instead
[2021-09-01 19:39:18][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:18][info][trt_builder.cpp:690]:Build done 32689 ms !
[2021-09-01 19:39:18][warn][trt_builder.cpp:33]:NVInfer WARNING: The logger passed into createInferRuntime differs from one already assigned, 0x557f9ae330b0, logger not updated.
[2021-09-01 19:39:19][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:19][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:19][info][trt_infer.cpp:169]:Infer 0x7fe3f8000c40 detail
[2021-09-01 19:39:19][info][trt_infer.cpp:170]: Max Batch Size: 1
[2021-09-01 19:39:19][info][trt_infer.cpp:171]: Dynamic Batch Dimension: false
[2021-09-01 19:39:19][info][trt_infer.cpp:172]: Inputs: 1
[2021-09-01 19:39:19][info][trt_infer.cpp:176]: 0.images : shape {1 x 3 x 640 x 640}
[2021-09-01 19:39:19][info][trt_infer.cpp:179]: Outputs: 1
[2021-09-01 19:39:19][info][trt_infer.cpp:183]: 0.output : shape {1 x 8400 x 85}
[2021-09-01 19:39:19][info][app_yolo.cpp:94]:Save to YoloX_result/car.jpg, 2 object, 10.10 ms
[2021-09-01 19:39:19][info][app_yolo.cpp:94]:Save to YoloX_result/group.jpg, 1 object, 6.19 ms
[2021-09-01 19:39:19][info][app_yolo.cpp:94]:Save to YoloX_result/zand.jpg, 2 object, 8.72 ms
[2021-09-01 19:39:19][info][app_yolo.cpp:94]:Save to YoloX_result/zgjr.jpg, 3 object, 6.03 ms
[2021-09-01 19:39:19][info][app_yolo.cpp:94]:Save to YoloX_result/gril.jpg, 1 object, 5.95 ms
[2021-09-01 19:39:19][info][app_yolo.cpp:94]:Save to YoloX_result/yq.jpg, 1 object, 5.92 ms
[2021-09-01 19:39:19][info][yolo.cpp:214]:Engine destroy.
[2021-09-01 19:39:19][info][app_yolo.cpp:277]:===================== test YoloX fp16 ==================================
[2021-09-01 19:39:19][info][trt_builder.cpp:473]:Compile FP16 Onnx Model 'yolox_s.onnx'.
[2021-09-01 19:39:19][warn][trt_builder.cpp:483]:Platform not have fast fp16 support
[2021-09-01 19:39:19][info][trt_builder.cpp:602]:Input shape is 1 x 3 x 640 x 640
[2021-09-01 19:39:19][info][trt_builder.cpp:603]:Set max batch size = 1
[2021-09-01 19:39:19][info][trt_builder.cpp:604]:Set max workspace size = 1024.00 MB
[2021-09-01 19:39:19][info][trt_builder.cpp:605]:Dynamic batch dimension is false
[2021-09-01 19:39:19][info][trt_builder.cpp:608]:Network has 1 inputs:
[2021-09-01 19:39:19][info][trt_builder.cpp:614]: 0.[images] shape is 1 x 3 x 640 x 640
[2021-09-01 19:39:19][info][trt_builder.cpp:620]:Network has 1 outputs:
[2021-09-01 19:39:19][info][trt_builder.cpp:625]: 0.[output] shape is 1 x 8400 x 85
[2021-09-01 19:39:19][info][trt_builder.cpp:670]:Building engine...
[2021-09-01 19:39:19][warn][trt_builder.cpp:33]:NVInfer WARNING: Half2 support requested on hardware without native FP16 support, performance will be negatively affected.
[2021-09-01 19:39:19][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:19][warn][trt_builder.cpp:33]:NVInfer WARNING: Detected invalid timing cache, setup a local cache instead
[2021-09-01 19:39:47][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:47][info][trt_builder.cpp:690]:Build done 28282 ms !
[2021-09-01 19:39:47][warn][trt_builder.cpp:33]:NVInfer WARNING: The logger passed into createInferRuntime differs from one already assigned, 0x557f9ae330b0, logger not updated.
[2021-09-01 19:39:48][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:48][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:48][info][trt_infer.cpp:169]:Infer 0x7fe3f8015650 detail
[2021-09-01 19:39:48][info][trt_infer.cpp:170]: Max Batch Size: 1
[2021-09-01 19:39:48][info][trt_infer.cpp:171]: Dynamic Batch Dimension: false
[2021-09-01 19:39:48][info][trt_infer.cpp:172]: Inputs: 1
[2021-09-01 19:39:48][info][trt_infer.cpp:176]: 0.images : shape {1 x 3 x 640 x 640}
[2021-09-01 19:39:48][info][trt_infer.cpp:179]: Outputs: 1
[2021-09-01 19:39:48][info][trt_infer.cpp:183]: 0.output : shape {1 x 8400 x 85}
[2021-09-01 19:39:48][info][app_yolo.cpp:94]:Save to YoloX_result/car.jpg, 2 object, 10.75 ms
[2021-09-01 19:39:48][info][app_yolo.cpp:94]:Save to YoloX_result/group.jpg, 1 object, 6.38 ms
[2021-09-01 19:39:48][info][app_yolo.cpp:94]:Save to YoloX_result/zand.jpg, 2 object, 9.12 ms
[2021-09-01 19:39:48][info][app_yolo.cpp:94]:Save to YoloX_result/zgjr.jpg, 3 object, 6.10 ms
[2021-09-01 19:39:48][info][app_yolo.cpp:94]:Save to YoloX_result/gril.jpg, 1 object, 6.07 ms
[2021-09-01 19:39:48][info][app_yolo.cpp:94]:Save to YoloX_result/yq.jpg, 1 object, 6.01 ms
[2021-09-01 19:39:48][info][yolo.cpp:214]:Engine destroy.
[2021-09-01 19:39:48][info][app_yolo.cpp:190]:===================== test YoloX int8 ==================================
[2021-09-01 19:39:48][info][trt_builder.cpp:473]:Compile INT8 Onnx Model 'yolox_s.onnx'.
[2021-09-01 19:39:48][info][trt_builder.cpp:593]:Using image list[6 files]: inference
[2021-09-01 19:39:48][info][trt_builder.cpp:602]:Input shape is 1 x 3 x 640 x 640
[2021-09-01 19:39:48][info][trt_builder.cpp:603]:Set max batch size = 1
[2021-09-01 19:39:48][info][trt_builder.cpp:604]:Set max workspace size = 1024.00 MB
[2021-09-01 19:39:48][info][trt_builder.cpp:605]:Dynamic batch dimension is false
[2021-09-01 19:39:48][info][trt_builder.cpp:608]:Network has 1 inputs:
[2021-09-01 19:39:48][info][trt_builder.cpp:614]: 0.[images] shape is 1 x 3 x 640 x 640
[2021-09-01 19:39:48][info][trt_builder.cpp:620]:Network has 1 outputs:
[2021-09-01 19:39:48][info][trt_builder.cpp:625]: 0.[output] shape is 1 x 8400 x 85
[2021-09-01 19:39:48][info][trt_builder.cpp:670]:Building engine...
[2021-09-01 19:39:48][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:49][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:49][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:39:49][info][app_yolo.cpp:193]:Int8 1 / 6
[2021-09-01 19:39:49][info][app_yolo.cpp:193]:Int8 2 / 6
[2021-09-01 19:39:49][info][app_yolo.cpp:193]:Int8 3 / 6
[2021-09-01 19:39:49][info][app_yolo.cpp:193]:Int8 4 / 6
[2021-09-01 19:39:49][info][app_yolo.cpp:193]:Int8 5 / 6
[2021-09-01 19:39:50][info][app_yolo.cpp:193]:Int8 6 / 6
[2021-09-01 19:40:27][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:40:27][warn][trt_builder.cpp:33]:NVInfer WARNING: Detected invalid timing cache, setup a local cache instead
[2021-09-01 19:40:59][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:40:59][info][trt_builder.cpp:685]:No set entropyCalibratorFile, and entropyCalibrator will not save.
[2021-09-01 19:40:59][info][trt_builder.cpp:690]:Build done 70917 ms !
[2021-09-01 19:40:59][warn][trt_builder.cpp:33]:NVInfer WARNING: The logger passed into createInferRuntime differs from one already assigned, 0x557f9ae330b0, logger not updated.
[2021-09-01 19:40:59][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:40:59][warn][trt_builder.cpp:33]:NVInfer WARNING: TensorRT was linked against cuBLAS/cuBLAS LT 11.4.2 but loaded cuBLAS/cuBLAS LT 11.4.1
[2021-09-01 19:40:59][info][trt_infer.cpp:169]:Infer 0x7fe3b4000c40 detail
[2021-09-01 19:40:59][info][trt_infer.cpp:170]: Max Batch Size: 1
[2021-09-01 19:40:59][info][trt_infer.cpp:171]: Dynamic Batch Dimension: false
[2021-09-01 19:40:59][info][trt_infer.cpp:172]: Inputs: 1
[2021-09-01 19:40:59][info][trt_infer.cpp:176]: 0.images : shape {1 x 3 x 640 x 640}
[2021-09-01 19:40:59][info][trt_infer.cpp:179]: Outputs: 1
[2021-09-01 19:40:59][info][trt_infer.cpp:183]: 0.output : shape {1 x 8400 x 85}
[2021-09-01 19:40:59][info][app_yolo.cpp:94]:Save to YoloX_result/car.jpg, 0 object, 7.75 ms
[2021-09-01 19:40:59][info][app_yolo.cpp:94]:Save to YoloX_result/group.jpg, 0 object, 4.04 ms
[2021-09-01 19:40:59][info][app_yolo.cpp:94]:Save to YoloX_result/zand.jpg, 0 object, 6.04 ms
[2021-09-01 19:40:59][info][app_yolo.cpp:94]:Save to YoloX_result/zgjr.jpg, 0 object, 3.74 ms
[2021-09-01 19:40:59][info][app_yolo.cpp:94]:Save to YoloX_result/gril.jpg, 0 object, 3.72 ms
[2021-09-01 19:40:59][info][app_yolo.cpp:94]:Save to YoloX_result/yq.jpg, 0 object, 3.74 ms
[2021-09-01 19:40:59][info][yolo.cpp:214]:Engine destroy.
Time-consuming in the FP16/FP32 modes is close, is it because the code I wrote has a problem?
Your sincerely!