Darknet版yolov3训练自己的数据集

一、在darknet文件夹下建立VOC格式目录

    VOCdevkit
        VOC2028
            Annotations
            JPEGImages
            ImageSets
                Main

二、将数据移到VOC目录下

    cp *.jpg ~/darknet/VOCdevkit/VOC2028/JPEGImages
    cp *.xml ~/darknet/VOCdevkit/VOC2028/Annotations

    将所有脚本拷贝到cp  *  ~/darknet/VOCdevkit/VOC2028

三、在终端运行Main_devide.py

    cd ~/darknet/VOCdevkit/VOC2028
    python3 Main_devide.py /home/town/darknet/VOCdevkit/VOC2028

四、检验数据集

    复制文件  检查图片是否损坏.py  到   VOC2028所在文件夹
    终端运行:python3 检查图片是否损坏.py

    复制文件  检查XML文件是否出现无效框.py  到   VOC2028所在文件夹
    终端运行:python3 检查XML文件是否出现无效框.py
    
    复制文件  对比数量是否一致.py  到  VOC2028所在文件夹
    终端运行:python3 对比数量是否一致.py

五、将voc_label.py复制到darknet目录下

    cp ~/darknet/scripts/voc_label.py  ~/darknet
    
    将:sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
    改为:sets=[('2028', 'train'), ('2028', 'val'), ('2028', 'test')]
    
    classes=["需要训练的类别名称"]
    
    最后两行:os.system("cat 2007_train.txt 2007_val.txt 2012_train.txt 2012_val.txt > train.txt")
             os.system("cat 2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt > train.all.txt")
    改为:os.system("cat 2028_train.txt 2028_val.txt > train.txt")
         os.system("cat 2028_train.txt 2028_val.txt 2028_test.txt  > train.all.txt")
    
    改完后保存,darknet打开终端运行:python3 voc_label.py
    复制darknet下的5个新文件到 VOCdevkit 中

六、在darknet文件夹新建 VOC_train_core 文件夹

    cp  ~/darknet/cfg/voc.data  ~/darknet/VOC_train_core
    cp  ~/darknet/data/voc.names  ~/darknet/VOC_train_core
    
    cp  ~/darknet/cfg/yolov3.cfg ~/darknet/VOC_train_core/yolo-obj.cfg
    
    #修改yolo-obj.cfg:
    batch=16                 (根据显存,或者2的倍数)
    subdivisions=16          (根据显存,或者2的倍数)
    width=416                (32的倍数)
    height=416               (32的倍数)
    
    max_batches = 24000      (类别数量*2000)
    steps=19200,21600        (0.8*max_batches,0.9*max_batches)
    
    搜索yolo,有3个地方
    filters=39               ( (类别数量+5)*3 )
    classes=8                (类别数量)

###batch=64 每batch个样本更新一次参数。
###subdivisions=16 如果内存不够大,将batch分割为subdivisions个子batch,每个子batch的大小为batch/subdivisions。

七、修改voc.data 和 voc.name 文件

    train  = /home/town/darknet/VOCdevkit/train.txt
    valid  = /home/town/darknet/VOCdevkit/2028_test.txt
    names = /home/town/darknet/VOC_train_core/voc.names
    backup = /home/town/darknet/backup/

八、开始训练

cd ~/darknet

    新的训练:
    ./darknet detector train /home/town/darknet/VOC_train_core/voc.data /home/town/darknet/VOC_train_core/yolo-obj.cfg -map
    
    断点训练:
    ./darknet detector train /home/town/darknet/VOC_train_core/voc.data /home/town/darknet/VOC_train_core/yolo-obj.cfg /home/town/darknet/backup/yolo-obj_last.weights -map
    
    补充训练:
    ./darknet detector train /home/town/darknet/VOC_train_core/voc.data /home/town/darknet/VOC_train_core/yolo-obj.cfg /home/town/darknet/backup/yolo-obj_final.weights -clear -map

九、查看训练效果

    cd ~/darknet
   
   ./darknet detector map /home/town/darknet/VOC_train_core/voc.data /home/town/darknet/VOC_train_core/yolo-obj.cfg /home/town/darknet/backup/yolo-obj_last.weights

备注:
./darknet detector test [-thresh] [-out]
./darknet detector train [-thresh] [-gpu] [-gpus] [-clear]
./darknet detector valid [-out] [-thresh]
./darknet detector recall [-thresh]

'<>'必选项,’[ ]‘可选项

data_cfg:数据配置文件,eg:cfg/voc.data

models_cfg:模型配置文件,eg:cfg/yolov3-voc.cfg

weights:权重配置文件,eg:weights/yolov3.weights

test_file:测试文件,eg://*/test.txt

-thresh:显示被检测物体中confidence大于等于 [-thresh] 的bounding-box,默认0.005

-out:输出文件名称,默认路径为results文件夹下,eg:-out “” //输出class_num个文件,文件名为class_name.txt;若不选择此选项,则默认输出文件名为comp4_det_test_“class_name”.txt

-i/-gpu:指定单个gpu,默认为0,eg:-gpu 2

-gpus:指定多个gpu,默认为0,eg:-gpus 0,1,2

 ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
 ./darknet detector demo coco.data ./cfg/yolov3.cfg ./yolov3.weights 1.avi

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