DarkNet
Joseph Redmon showcased DarkNet at TED2017. Less than a decade ago classification problems between a cat or dog was almost impossible, but advances in deep learning has changed that. Joseph worked on YOLO which is a revolutionary system that can identify objects it has been trained on, and it does it incredibly fast.
Fast enough and accurate enough to track objects in live video feeds. This technology can be employed in self-driving cars, CCTV cameras, factory lines etc.
How to install
Joseph has a pretty good guide on his website. But I will explain some of the main steps I did. If you want to just try YOLO on one image, then you can just clone the repo, complile and run. If you want to use the live feed feature and use a GPU then things get a bit more tricky. Spoiler alert: The hardest part is installing CUDA
Installing CUDA
I used Ubuntu 17.04(64 bit), to perform parallel computing on the GPU you will need CUDA
Nvidia Installation Instructions
Pre-Install Instructions
I installed cuda 9.1. deb(local).
Make sure you have a CUDA capabale GPU by looking up your GPU model here
Make sure you have gcc
installed
username@hostname:~$ gcc --version
Install kernel headers and dev packages by issuing:
username@hostname:~$ sudo apt-get install linux-headers-$(uname -r)
CUDA Installation
You can install the .deb you downloaded by issuing:
username@hostname:~$ sudo dpkg -i cuda-repo-<distro>_<version>_<architecture>.deb
username@hostname:~$ sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
username@hostname:~$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/<distro>/<architecture>/7fa2af80.pub
username@hostname:~$ sudo apt-get update
username@hostname:~$ sudo apt-get install cuda
CUDA Post Install Instructions
Set up the environment and etc by issuing:
username@hostname:~$ export PATH=/usr/local/cuda-9.1/bin${PATH:+:${PATH}}
username@hostname:~$ export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64\ {LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Some Power9 Stuff you may need to do as well.
Make a file /usr/lib/systemd/system/nvidia-persistenced.service
, I recommend using nano,
Containing:
[Unit]
Description=NVIDIA Persistence Daemon
Wants=syslog.target
[Service]
Type=forking
PIDFile=/var/run/nvidia-persistenced/nvidia-persistenced.pid
Restart=always
ExecStart=/usr/bin/nvidia-persistenced --verbose
ExecStopPost=/bin/rm -rf /var/run/nvidia-persistenced
[Install]
WantedBy=multi-user.target
Then run the command:
username@hostname:~$ sudo systemctl enable nvidia-persistenced
Next, we should install Persistence Daemon. I didn’t do this initially and had to change BIOS settings for graphics to Discrete from Hybrid, which made my battery life very bad. Or it doesn’t boot up, So it’s worth doing all the steps Nvidia recommends.
username@hostname:~$ /usr/bin/nvidia-persistenced --verbose
Verification
If everything worked out then when you issue the following you shouldn’t get an error
username@hostname:~$ cat /proc/driver/nvidia/version
Troubleshooting
I had a weird problem where CUDA would install gcc-7 but wouldn’t let me compile with it. Instead I had to compile using gcc-6. In this case you will need to change your gcc
symbolic link.
Remove existing links
rm /usr/bin/gcc
rm /usr/bin/g++
ln -s /usr/local/bin/gcc-6 gcc
ln -s /usr/local/bin/g++-6 g++
OR
~/.bash_profile
alias gcc='gcc-6'
alias g++='g++-6'
Hopefully that works!
OpenCV
OpenCV is a computer vision library. It’s state of the art. We will need to install this too. But this is easy.
sudo apt-get install libopencv-dev
You can check if that worked by issuing:
pkg-config --modversion opencv
Compiling DarkNet
First, issue make
, then if there are no errors change GPU=1
, if remaking shows no errors then try OPENCV=1
.
YOLO
Everything should be set up. You can call the YOLO software with the webcam by running:
./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights