YOLOv4配置和训练

YOLOv4配置和训练

下载地址:https://github.com/AlexeyAB/darknet

依赖环境

  • CMake >= 3.12
  • CUDA >= 10.0
  • cuDNN >= 7.0
  • OpenCV >= 2.4
  • GPU with CC >= 3.0
  • on linux GCC or Clang, on Windows MSVC 2017/2019

编译

目录下修改 Makefile 文件,按照需要选择是否打开相应的选择:

  • GPU = 1
  • CUDNN = 1
  • CUDNN_HALF = 1
  • OPENCV = 1
  • DEBUG = 1
  • LIBSO = 1
  • ZED_CAMERA = 1

make 即可。

测试

测试一下安装环境是否完好。

./darknet detect cfg/yolov4.cfg yolov4.weights data/dog.jpg

修改相关数据集

https://github.com/VisDrone/VisDrone-Dataset

使用的数据集已经标注好,需要修改相关格式符合YOLO训练的要求。

YOLO训练需要的数据如下:

  • 待训练图像images

  • 和图像同名的 txt 文件, 内部格式要求

    • 目标的类别,0 ~ classes - 1

    • - float values relative to width and height of image, it can be equal from (0.0 to 1.0],计算bounding box 关于整图的比例,即中心点的位置以及bounding box 的长宽/图像长宽。

      举个例子: = / or = /

      一个txt里面的内容可能是:

      1 0.716797 0.395833 0.216406 0.147222
      0 0.687109 0.379167 0.255469 0.158333
      1 0.420312 0.395833 0.140625 0.166667
      
  • 一个总览的 train.txt ,里面存放所有图像的路径,如下。程序根据路径就可以找到图片以及对应的txt。

    data/obj/img1.jpg
    data/obj/img2.jpg
    data/obj/img3.jpg
    
  • 一个 obj.names 文件,里面存放需要训练的物体的类别,一行一个,诸如:

    car
    bicycle
    motor
    ...
    
  • 一个 obj.data 文件,总览上述所有文件

    classes = 2  #类别数目
    train  = data/train.txt  # 图像路径,可以找到jpg和对应的txt
    valid  = data/test.txt
    names = data/obj.names  #类别名字
    backup = backup/ #存放训练结果
    

但是,下载的数据集的格式如下:

684,8,273,116,0,0,0,0
406,119,265,70,0,0,0,0

,,,,     ,
=========================================================================================
    Name                                                  Description
-----------------------------------------------------------------------------------------  	  The x coordinate of the top-left corner of the predicted bbox

	   The y coordinate of the top-left corner of the predicted object bbox

   The width in pixels of the predicted object bounding box

  The height in pixels of the predicted object bounding box

	       The score in the DETECTION file indicates the confidence of the predicted bounding box enclosing an object instance. The score in GROUNDTRUTH file is set to 1 or 0. 1 indicates the bounding box is considered in evaluation, while 0 indicates the bbox will be ignored.
                      
    The object category indicates the type of annotated object, (i.e., ignored regions(0), pedestrian(1), people(2), bicycle(3), car(4), van(5), truck(6), tricycle(7), awning-tricycle(8), bus(9), motor(10), others(11))
                                    

已知的类别有:

regions(0), pedestrian(1), people(2), bicycle(3), car(4), van(5), truck(6), tricycle(7), awning-tricycle(8), bus(9), motor(10), others(11)

相关文件

1.复制文件yolov4-custom.cfg改名为yolo-obj.cfg,并修改关于类别的参数。

2.build\darknet\x64\data\目录下创建obj.names,每个对象名称都在新的一行

3.build\darknet\x64\data\目录下创建obj.data

4.将对象的图像文件(.jpg)放在目录 build\darknet\x64\data\obj\

5.build\darknet\x64\data\目录下创建train.txt包含所有图片的路径以及名称

6.下载卷积层的预训练权重yolov4.conv.137并放入目录 build\darknet\x64

7.训练命令: ./darknet detector train data/obj.data yolo-obj.cfg yolov4.conv.137

8.训练完成后,从路径build\darknet\x64\backup\获取结果yolo-obj_final.weights

制作自己的数据集。

首先对于我们拍摄的图像,要进行标定,使用软件 labelImg 得到标定后的文件为 .xml格式,利用一个Python脚本将其转化为.txt格式。

之后数据集的制作如上所述。

你可能感兴趣的:(深度学习,计算机视觉)