-
Notifications
You must be signed in to change notification settings - Fork 8k
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.
-
Get file
csdarknet53-omega.conv.105
- The first 105 layers from the pre-trained weights on ImageNet (ILSVRC2012):- download weights
csdarknet53-omega_final.weights
for Classifier: https://drive.google.com/open?id=18jCwaL4SJ-jOvXrZNGHJ5yz44g9zi8Hm - get only the first 105 layers
./darknet partial cfg/csdarknet53-omega.cfg csdarknet53-omega_final.weights csdarknet53-omega.conv.105 105
- download weights
-
Download The Pascal VOC Data and unpack it to directory
/voc/
will be created dir/voc/VOCdevkit/
:- http://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar
- http://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar
- http://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar
2.1 Download file
voc_label.py
: http://pjreddie.com/media/files/voc_label.py -
Download and install Python for Windows (or Linux): https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe
-
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) -
Run command:
type 2007_train.txt 2007_val.txt 2012_*.txt > train.txt
-
If required change paths in the file
cfg/voc.data
- 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)
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
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 runvoc_label_difficult.py
to get the filedifficult_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:
- Using Darknet + Python: run the file
build/darknet/x64/calc_mAP_voc_py.cmd
- you will get mAP foryolo-voc.cfg
model, mAP = 75.9% - Using this fork of Darknet: run the file
build/darknet/x64/calc_mAP.cmd
- you will get mAP foryolo-voc.cfg
model, mAP = 75.8%
- Using Darknet + Python: run the file
-
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
andvoc_eval.py
instead ofreval_voc_py3.py
andvoc_eval_py3.py
from this directory: https://github.com/AlexeyAB/darknet/tree/master/scripts