Getting started with YOLOv3 (Machine Learning), Part 1
Recently I posted this image on Reddit and I got a lot of requests for a simple guide on how to get something like this working.
What you need:
- A virtual machine / bare metal server with reasonable power
- Ubuntu 18.04 (will most likely work 16.04 upwards)
- The expectation that it will not work at 'real time' framerates unless you have a decent GPU (Titan X onwards)
- Some images to run.
- Yolov3 or a fork (this is the one I will be using)
- Pre-trained weight file (237mb)
- Time and coffee.
Create a VM
I've got a couple of servers running VMWare ESXI 6.7 in the Lab, below is the basic sizing of the vm for yolov3
As I do not have a GPU in the server (or a card capable of vGPU) I'm simply assigning the virtual machine 2 CPU's (with 2 cores each) and 16GB of ram. I've also given it 30GBs of storage on a flash raid array. A fairly modest config like this is fine for showing Yolov3 running in a basic way.
I'll assume you know how to setup a vanilla ubuntu install (if not then there's loads of tutorials on youtube etc or just stick to AWS).
Now we've got a our vm ready we can install Darknet (https://pjreddie.com/darknet/), this is the Neural Network framework that YOLOv3 uses. Firstly, make sure your vm is updated.
sudo apt update sudo apt upgrade
Now we need to make sure we have the build tools installed so that we can compile software from source.
sudo apt install make sudo apt install build-essential
I've chosen to use a fork instead of the original as it contains some more features and fixes, these instructions should however work with both.
Note, I'm not going to compile with OpenCV or CUDA as we're not running this on a GPU and it's just a demo. Once I buy a GPU for the server I'll do another post.
The original project is at :
Anyway, drop into a shell on your new vm and run the following commands:
git clone https://github.com/AlexeyAB/darknet.git cd darknet/ make
This will leave you with a darknet binary which you can then run
Now that we have confirmed that darknet is built correctly, we need to download the pre-trained weights model.
Note, there are multiple weights models available, I have picked the most comprehensive (however it also takes the longest)
# Make sure you're in the darknet directory wget https://pjreddie.com/media/files/yolov3.weights
Checkout the 'Pre-trained models' section of this page https://github.com/alexeyab/darknet for more options.
Now you need to upload some images to your server, grab some from google or supply your own camera frame grabs.
./darknet detector test ./cfg/coco.data ./cfg/yolov3.cfg yolov3.weights -ext_output 2.png
You'll get an output showing the location of each object and what it thinks that the object is (along with it's confidence rating). A graphical representation is shown in the 'predictions.png' file.
However you can set it to ignore predictions with a confidence rating less than you define.
Hopefully this was useful, I appreciate it's a very basic intro on how to get YOLOv3 running. In the future I'd like to run it at around 30fps and feed it's output into other systems. But, I'll need a decent GPU for that!
I'm also going to try and train my own model, going to start with training it to recognize my own car. I would also like to extend YOLO so that it can tell me the color of the detected object, for example, I'd love it to say 'Car - White' etc.