YOLO 训练和 检测技巧

注意根据特定任务对 anchor 进行修改,方法参考
https://github.com/pjreddie/darknet/issues/911
./darknet detector calc_anchors data/hand.data -num_of_clusters 9 -width 704 -height 576 -show

https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects
这个文档给出了 一些提高精度 的方法

提高物体检测性能的方法:
训练前

1 cfg 文件中 设置 random = 1

2 提高 cfg中指定的分辨率, 比如 height = 608, width = 608 或者更高的32的倍数

3 确保 每个样本都有标注并且正确标注

4 对于待检测的物体, 训练集中 要有 相似物体, 形状、大小、旋转角度、倾斜、明亮度 方面相似
包含 物体 在不同尺度、旋转、照片、侧面、和背景 下的图像 有利于训练, 每个类别至少2000张不同的图像
至少训练 2000*类别数 次

5 提高 不包含待检测物体的 图像 也很重要, 就是 负样本,这些样本对应的txt为空文件,
负样本的数量 最好和 正样本数量 一致。 这条容易被 忽略

6 如果单张图像里面需要检测出的物体比较多,那么设置yolo层和region层中 max=200 或者更大值

7 如果是检测小物体(图像resize为416*416 后,小于 16*16 像素), 那么在 yolov3.cfg中720 行设置 layers = -1, 11
并且, 717行 设置 stride 为4

8 如果训练 既有大物体又有小物体的模型, 那么 使用 yolov3_5l.cfg, 这个有 5 yolo层
如果用 tiny模型,那么使用 yolov3-tiny_3l.cfg,
如果用 Spatial-full-model, 那么用 yolov3-spp.cfg

9 如果是训练需要区分左右的物体, 那么 禁用 flip , yolov3cfg 第17行 设置 flip = 0

10 一般来说, 训练集中物体大小和待检测图像中物体大小 有一定约束,大致关系为
train_network_width * train_obj_width / train_image_width ~= detection_network_width * detection_obj_width / detection_image_width
train_network_height * train_obj_height / train_image_height ~= detection_network_height * detection_obj_height / detection_image_height

也就是说, 如果训练集中物体宽度占图像的比例 要约等于 测试集中物体宽度占图像的比例

11 如果要加速训练(可能会降低精度), 使用 fine-tuning,而不是迁移学习, 设置 548 行 stopbackward=1
执行命令: ./darknet partial cfg/yolov3.cfg yolov3.weights yolov3.conv.81 81 will be created file yolov3.conv.81, then train by using weights file yolov3.conv.81 instead of darknet53.conv.74

12 ?? 检测的物体越不同, 使用的网络模型就应该 越复杂

13 针对cfg 文件中的 高宽 重新计算 anchor:darknet.exe detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height 416
然后设置 yolo层 中的 anchor . 需要修改 masks , 是的第一个 yolo层的anchor 大于60*60, 第二个 大于 30*30,第三个保持不变
同时 要修改 yolo层前面 filters 的个数,公式为

 filters=(classes + 5)*

训练好之后, 对于检测:
增加 cfg 分辨率(依然设为 32的倍数 ), 这能提高准确率和检测到小物体的概率
这并不需要重新训练网络, 指定高宽为416时 训练处的权重文件 即可

如果想要更高准确率,那么还是 在高分辨率时 进行训练, 如果 显示 out of memory ,那么 就 把cfg中 subdivisions 改大,比如 32, 64 等等

你可能感兴趣的:(深度学习,YOLO,训练,检测,精度)