Train and Evaluate Detector on Pascal VOC (VOCtrainval 2007 2012) dataset - Sudhakar17/darknet GitHub Wiki

Train and Evaluate Detector on Pascal VOC (VOCtrainval 2007+2012) dataset

Note: For using Mosaic data augmentation and to avoid the bottleneck of CPU performance for data augmentation, compile Darknet with OpenCV.

Train Detector on Pascal VOC (VOCtrainval 2007+2012) dataset

Required files:

  1. Get file csdarknet53-omega.conv.105 - The first 105 layers from the pre-trained weights on ImageNet (ILSVRC2012):

  2. Download The Pascal VOC Data and unpack it to directory /voc/ will be created dir /voc/VOCdevkit/:

    2.1 Download file voc_label.py: http://pjreddie.com/media/files/voc_label.py

  3. Download and install Python for Windows (or Linux): https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe

  4. Run command: python voc_label.py in the /voc/ folder (to generate files: 2007_test.txt, 2007_train.txt, 2007_val.txt, 2012_train.txt, 2012_val.txt)

  5. Run command: type 2007_train.txt 2007_val.txt 2012_*.txt > train.txt

  6. If required change paths in the file cfg/voc.data


Training

  • Training command:

./darknet detector train cfg/voc.data cfg/yolov4.cfg csdarknet53-omega.conv.105

  • Continue training:

./darknet detector train cfg/voc.data cfg/yolov4.cfg backup/yolov4_last.weights

(Note: To disable Loss-Window use flag -dont_show)

More information about training by the link: http://pjreddie.com/darknet/yolo/#train-voc

Note: If during training you see nan values for avg (loss) field - then training goes wrong, but if nan is in some other lines - then training goes well.

You will get files

  • chart.png with Loss chart
  • backup/yolov4_last.weights - trained last weights file
  • backup/yolov4_final.weights - trained final weights file (when training is complete)

Detection:

Detect on the image:

./darknet detector test cfg/voc.data cfg/yolov4.cfg backup/yolov4_final.weights dog.jpg -ext_output

Detect on the video-file:

./darknet detector demo cfg/voc.data cfg/yolov4.cfg backup/yolov4_final.weights test.mp4 -ext_output

Detect on the video-file by using GPU-1:

./darknet detector demo cfg/voc.data cfg/yolov4.cfg backup/yolov4_final.weights test.mp4 -ext_output -i 1

Detect on the RTSP/HTTP video-camera:

./darknet detector demo cfg/voc.data cfg/yolov4.cfg backup/yolov4_final.weights http://192.168.0.80:8080/video?dummy=param.mjpg -ext_output


Evaluate Detector on Pascal VOC (PascalVOC-2007-test) dataset

To calculate mAP (mean average precision) on PascalVOC-2007-test:

  • Download PascalVOC dataset, install Python 3.x and get file 2007_test.txt as described here in the Training stage

  • Then download file https://raw.githubusercontent.com/AlexeyAB/darknet/master/scripts/voc_label_difficult.py to the dir /voc/ then run voc_label_difficult.py to get the file difficult_2007_test.txt

  • Remove symbol # from line #difficult = data/difficult_2007_test.txt to un-comment it in: cfg/voc.data

  • Then there are 2 ways to get mAP:

    1. Using Darknet + Python: run the file build/darknet/x64/calc_mAP_voc_py.cmd - you will get mAP for yolo-voc.cfg model, mAP = 75.9%
    2. Using this fork of Darknet: run the file build/darknet/x64/calc_mAP.cmd - you will get mAP for yolo-voc.cfg model, mAP = 75.8%
  • if you have Python 2.x instead of Python 3.x, and if you use Darknet+Python-way to get mAP, then in your cmd-file use reval_voc.py and voc_eval.py instead of reval_voc_py3.py and voc_eval_py3.py from this directory: https://github.com/AlexeyAB/darknet/tree/master/scripts