Sunday, September 8, 2019

Deep learning in Ubuntu: Darknet YOLOv3

This post describes setting up object detection features of Darknet neural network framework, coupled with camera input, using the YOLOv3 pretrained network, designed by Joseph Redmon and Ali Farhadi, 2018.

The prerequisites are an ubuntu system, equipped with a GPU, with appropriate drivers, CUDA, and Opencv, as well as the Darknet tools.
All these are described in the previous posts.

1.Follow instructions from for weights download and testing with image based object detection.
I get errors in processing the image recognition samples

$ ./darknet detector test cfg/ cfg/yolov3.cfg cfg/yolov3.weights data/dog.jpg
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   608 x 608 x   3   ->   608 x 608 x  32  0.639 BFLOPs
    1 conv     64  3 x 3 / 2   608 x 608 x  32   ->   304 x 304 x  64  3.407 BFLOPs
    2 conv     32  1 x 1 / 1   304 x 304 x  64   ->   304 x 304 x  32  0.379 BFLOPs
    3 CUDA Error: out of memory
darknet: ./src/cuda.c:36: check_error: Assertion `0' failed.
Aborted (core dumped)

I retry with tiny model (i download the tiny network weights) and now it works
$ ./darknet detector test cfg/ cfg/yolov3-tiny.cfg cfg/yolov3-tiny.weights data/dog.jpg
Loading weights from cfg/yolov3-tiny.weights...Done!
data/dog.jpg: Predicted in 0.192830 seconds.
dog: 56%
car: 52%
truck: 56%
car: 62%
bicycle: 58%

It seems that the error comes from the network configurations in cfg/yolov3.cfg

Comparing the yolov3.cfg and the yolov3-tiny.cfg i managed to find parameter to have the network run correctly with the larger weight-set

I edited the first lines of yolov3.cfg as follows

# Testing
# Training

And now it works!
$ ./darknet detector test cfg/ cfg/yolov3.cfg cfg/yolov3.weights data/dog.jpg
Loading weights from cfg/yolov3.weights...Done!
data/dog.jpg: Predicted in 0.327576 seconds.
dog: 99%
truck: 93%
bicycle: 99%
(base) mgua@mgtp53s:~/darknet/darknet$ 

2.install mplayer to have the libraries required to access the camera feed
#apt update
#apt install mplayer
$./darknet detector demo cfg/ cfg/yolo-voc.cfg yolo-voc.weights
or, for light model
$./darknet detector demo cfg/ cfg/yolov3-tiny.cfg cfg/yolov3-tiny.weights

On my computer, with GPU Nvidia Quadro and CUDA I get about 6 FPS (frames per second) with the full weights set
and 16 FPS with the tiny model.

The following syntax should allow to use YOLO getting input from a network camera:

$./darknet detector demo cfg/ cfg/yolo-voc.cfg yolo-voc.weights rtsp://login:pass@ -i 0

No comments: