4. What's YOLO
You only look once (YOLO) is a state-of-the-art, real-time object detection system. On a Pascal Titan X
it processes images at 30 FPS and has a mAP of 57.9% on COCO test-dev.
The network divides the image into regions and predicts bounding boxes and probabilities for each
region. These bounding boxes are weighted by the predicted probabilities.
5. YOLOv3 is extremely fast and accurate. In mAP measured at .5 IOU YOLOv3 is on par with Focal Loss but
about 4x faster. Moreover, you can easily tradeoff between speed and accuracy simply by changing the
size of the model, no retraining required!
Comparison with Other Detectors
8. Darknet has two OPTIONAL dependencies:
• OpenCV if you want a wider variety of supported image types.
• CUDA and cuDNN if you want GPU computation.
Install Darknet
9. Install Darknet with GPU Support
Clone the repository and make:
$ git clone https://github.com/pjreddie/darknet
$ cd darknet
Edit the makefile and set GPU=1, CUDNN=1, OPENCV=1:
$ vim Makefile
Build:
$ make
Add the directory to ~/.bashrc:
export DARKNET_HOME=/home/ben/ProgTest/third-part/darknet
export PATH=$PATH:$DARKNET_HOME
$ source ~/.bashrc
https://pjreddie.com/darknet/yolo/
10. Test Darknet
Get pretrained model:
$ wget https://pjreddie.com/media/files/yolov3.weights
Edit cfg/yolov3.cfg to save the memory:
batch=1
subdivisions=1
width=416
height=416
Test YOLOv3:
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
!! Running YOLO on the CPU takes around 6-20 seconds
per image. It takes 0.082 seconds to run YOLO on GTX 960.
11. Detect Multiple Images
Leave the name of the image blank to try multiple images:
$ ./darknet detect cfg/yolov3.cfg yolov3.weights
Try different images e.g. data/eagle.jpg, data/dog.jpg, data/person.jpg,
or data/horses.jpg.
Use Ctrl-C to exit the program once you are done.
12. Changing The Detection Threshold
The default confidence of YOLO is 0.25 or higher.
You can change the threshold with -thresh flag:
$ ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg -thresh 0.1
Threshold=0.1Default
16. The PASCAL Visual Object Classes Challenge
The goal of this challenge is to recognize objects from a number of visual object classes in realistic
scenes (i.e. not pre-segmented objects). It is fundamentally a supervised learning learning problem
in that a training set of labelled images is provided.
17. Get The Pascal VOC Data
$ wget https://pjreddie.com/media/files/VOCtrainval_11-May-2012.tar
$ wget https://pjreddie.com/media/files/VOCtrainval_06-Nov-2007.tar
$ wget https://pjreddie.com/media/files/VOCtest_06-Nov-2007.tar
$ tar xf VOCtrainval_11-May-2012.tar
$ tar xf VOCtrainval_06-Nov-2007.tar
$ tar xf VOCtest_06-Nov-2007.tar
18. Generate Labels for VOC
Darknet wants a .txt file for each image with a line for each ground truth object in
the image that looks like:
<object-class> <x> <y> <width> <height>
Use Python script to generate the labels:
$ wget https://pjreddie.com/media/files/voc_label.py
$ python3 voc_label.py
The script generates a lot of label files in VOCdevkit/VOC2007/labels and
VOCdevkit/VOC2012/labels. The script also generates a text files which contains the
path of the images e.g. 2007_train.txt.
Set the targets to train YOLO:
$ cat 2007_train.txt 2007_val.txt 2012_*.txt > train.txt
19. Organize the Files and Folders
$ mv /voc_label.py VOCdevkit
$ mv *.txt VOCdevkit
The files and folders under VOCdevkit:
20. Edit the Configuration of Data
Edit cfg/voc.data:
classes= 20
train = <path-to-voc>/train.txt
valid = <path-to-voc>2007_test.txt
names = data/voc.names
backup = backup
data/voc.names contains the classes of VOC dataset.
21. Edit the Configuration of Model
Edit cfg/yolov3-voc.cfg:
# Testing
# batch=1
# subdivisions=1
# Training
batch=64
subdivisions=16
Train with VOC Dataset
Download the pretrained weight:
$ wget https://pjreddie.com/media/files/darknet53.conv.74
$ ./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74
22. Edit the Configuration and Test
Edit cfg/yolov3-voc.cfg:
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=16
Test the new model:
$ ./darknet detector test cfg/voc.data cfg/yolov3-voc.cfg backup/yolov3-voc_final.weights
VOCdevkit/VOC2007/JPEGImages/004948.jpg -thresh 0.1
26. YOLO3-4-Py is a Python wrapper of YOLO V3 Object Detector on Darknet which is also
compatible with other Darknet Object Detection models.
What's YOLO3-4-Py
http://absfreepic.com/free-photos/download/crowded-
vehicles-on-road-4752x3168_79207.html
27. Install YOLO3-4-Py
Add the variables to ~/.bashrc:
export DARKNET_HOME=/home/xxx/ooo/darknet/
export CUDA_HOME=/usr/local/cuda-9.0/
export PATH=${DARKNET_HOME}:${CUDA_HOME}bin:${PATH}
$ source ~/.bashrc
Install the share library and the header:
$ cd $DARKNET_HOME
$ sudo cp libdarknet.so /usr/lib
$ sudo cp include/darknet.h /usr/include
Installation from PyPI distribution:
$ sudo pip3 install yolo34py-gpu
https://github.com/madhawav/YOLO3-4-Py
29. Test YOLO3-4-Py
Test with the sample code:
$ cd $DARKNET_HOME
$ mkdir weights
$ cd weights
$ wget https://pjreddie.com/media/files/yolov3.weights
$ cd ..
$ python3 sampleApp.py
https://pypi.org/project/yolo34py/