Compiling Darknet on Arch
Darknet is an open source neural network framework written in C and CUDA. It is fast, easy to install, and supports CPU and GPU computation.
You have to compile Darknet to run YOLO. There were few hiccups that I faced while compiling Darknet on Arch with Nvidia GPU. I will detail out the procedure for the same.
The procedure of running compiling Darknet and running YOLO on CPU is easy and is listed on its website.
For Nvidia GPU
Assuming all the packages are installed in their default location.
Clone the Darknet repo.
git clone https://github.com/pjreddie/darknet.git cd darknet mkdir -o obj
Install OpenCV legacy version(
optdirectory version) from here.
Install CUDA from here. And add installed CUDA binaries to
# add this in ~/.bashrc export PATH="$PATH:/opt/cuda/bin"
darknet directoryand set GPU and OPENCV to 1.
#Makefile GPU=1 OPENCV=1
Change first occurance of
COMMONto the following:
LDFLAGS= -L/opt/cuda/lib64 -L/opt/opencv2/lib -lm -pthread -lstdc++ COMMON= -Iinclude/ -Isrc/ -I/opt/cuda/include
'ifeq ($(OPENCV), 1)'section change
COMMONto following and save it.
LDFLAGS+= -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui COMMON+= -I/opt/opencv2/include
make -j 8
If you have any errors, try to fix them or ask in comment box. If everything seems to have compiled correctly, try running it!
Download YOLOv3 pre-trained weights.
Try running it on input from a webcam.
LD_LIBRARY_PATH=/opt/opencv2/lib ./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights
We are setting
LD_LIBRARY_PATHso that the linker can find OpenCV’s dynamic libraries. Else it will show errors.
If you have less powerful GPU, like mine(I have MX 150), try running Tiny YOLOv3.
# download weights wget https://pjreddie.com/media/files/yolov3-tiny.weights # run the detector LD_LIBRARY_PATH=/opt/opencv2/lib \ ./darknet detect cfg/yolov3-tiny.cfg yolov3-tiny.weights data/dog.jpg