小目标检测使用TPH-YOLOv5 中的yolov5l-xs-tph.yaml模型;对其中的C3STR替换为C3模块;本文的TensorRT部署是基于yolov5l-xs-tph修改后的模型训练部署,其精度一般主要学习如何TensorRT部署,都是在wang-xinyu基础上简单修改;
TPH-YOLOv5 :https://github.com/cv516Buaa/tph-yolov5
yolov5l-xs-tph.yaml模型修改后:tensorrt-nyy: yolov5-6.0网络添加小目标检测头 TensorRT部署;
1、模型训练
具体修改在head 部分 anchors改为4; C3STR改为C3
anchors: 4
# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)
[ -1, 1, Conv, [ 128, 1, 1 ] ],
[ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
[ [ -1, 2 ], 1, Concat, [ 1 ] ], # cat backbone P2
[ -1, 2, C3, [ 128, False ] ], # 21 (P2/4-xsmall) #C3STR
[ -1, 1, Conv, [ 128, 3, 2 ] ],
[ [ -1, 18, 4], 1, Concat, [ 1 ] ], # cat head P3
[ -1, 2, C3, [ 256, False ] ], # 24 (P3/8-small)
[-1, 1, Conv, [256, 3, 2]],
[[-1, 14, 6], 1, Concat, [1]], # cat head P4
[-1, 2, C3, [512, False]], # 27 (P4/16-medium) #C3STR
[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 2, C3, [1024, False]], # 30 (P5/32-large) #C3STR
[[21, 24, 27, 30], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
yolov5l-xs-tph.yaml模型修改后训练60epoch后的模型,其精度一般,训练数据使用VisDrone2019。按照大神wang-xinyu的步骤转换即可。
2、模型转换
主要修改的地方:具体细节参考:tensorrt-nyy: yolov5-6.0网络添加小目标检测头 TensorRT部署;
CHECK_COUNT=3 修改为 CHECK_COUNT=4;
TensorRT 层的添加主要在第17层以后的18-31层添加修改;
在scale = 8 修改为 scale = 4;
修改后测试图片如下:
3、存在的问题
现在转换的模型对大目标检测不准;原因有待分析,可能与tensorrt转换有关,待以后分析