Danny
Danny Data Scientist

Using YOLO for Object Detection

This post follows through instructions for using YOLO (You Only Look Once) with video object detection. This demonstration was done with a g3.8xlarge Deep Learning AMI (Ubuntu) Version 6.0 (ami-bc09d9c1). The weights for this particular YOLO model were trained on the COCO dataset, which consists of 182 different labels.

Requirements

  • Python 3.5 or 3.6
  • TensorFlow
  • openCV

GitHub Repo

  • Download the GitHub repo from https://github.com/thtrieu/darkflow. Further instructions for downloading specific sets of weights can be found on the README file of the repo.

Build the Library

  • Create a build folder from the location of the repo with the following command
1
2
cd darkflow
python setup.py build_ext inplace
  • Create a new folder called ‘bin’ within the darkflow directory and place the weights into the bin folder.

Processing a Video

The below code assumes a video called video1.mp4 is uploaded in a data folder. You will also need to make sure that you have the proper cfg and weight files in the respective folders. In this case, the model that I am using is yolo.cfg and yolov2.weights.

If using CPU, you can get rid of the GPU flag any the threshold can be changed or removed. For a 1 minute video on a g3.8xlarge machine, it took roughly 10 minutes for the video to fully complile at a rate of 3.04 frames per second.

1
python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo data/video1.mp4 --threshold 0.25 --gpu 1.0 --saveVideo

Results

YOLO Example

Video from MLB.com. Full video can be seen here.


Walking down Michigan Avenue in Chicago.


comments powered by Disqus