Hey, glad you made it. So I’ve been messing around with YOLO, or the “You Only Look Once” real-time image detection program that uses machine learning with tensorflow and openCV. In this tutorial I will show you how you how to get started using YOLO and show you how to analyze any video you want. So lets get started.

This tutorial is a bit more advanced, so if you’re not relatively comfortable with Python and navigating around the terminal, I would recommend brushing up on those topics real quick. This tutorial focuses on running YOLO on a windows machine.

This is an example of what YOLO is capable of:

  • Alright, first off we need to get Python version 3.6. This is important because tensorflow won’t run on Python 3.7 yet. So go to this link and download the Python 3.6 package.
  • NOTE: it is very important you get the right version. It should look like this:

  • Alright, now we need to install Anaconda. Follow this link and download the appropriate version for your OS.
  • So there are two main ways to run tensorflow. You can either run the CPU version, which uses your systems CPU to process data. Or you can use the GPU version, which is far superior assuming you have a decent graphics card in your system. For this tutorial I will use the GPU version, however you can still do this with the CPU version, it will just take much longer and will significantly throttle your computers speed.

  • In order to use the GPU version of tensorflow we will need a few things.
  • 1. An Nvidia graphics card. It must be newer that the GTX 650.
    2. The CUDA Toolkit 9.0 (make sure you get 9.0 and not 9.1). Download this first.
    3. CUDNN 7.0.5. Download this second.
    4. Finally we need the Tensorflow 1.5 wheel. Download this third.

    CUDA tool kit should look like this:
    CUDNN should look like this:
    And the tensorflow file should look like this:

  • When you download CUDA, just click through the installer and once it finishes, you will need to restart your computer before downloading CDUNN. When you run the CUDA installer the first thing that will pop up is this:

    Leave the install path how it is. no need to change it.
  • Ok, after you have downloaded and run those packages, we still need to get openCV. To do this follow this link and search for “openCV.” You should find this:

    Download the one with the red arrow next to it. Then open the command prompt and navigate to the file and type pip install open and press ‘tab’ to auto complete the line. Hit enter and it will install itself.
  • Cool, now we need the actual YOLO program itself. So go to the YOLO github page. You can click the ‘Clone or Download’ button and copy the url, then create a new file and name it something like ‘YOLO_project’. Navigate to the folder in command prompt and type git clone https://github.com/thtrieu/darkflow. You should see something like this:
  • Cool beans. Now we need to change directory to the darkflow file, so type cd darkflow. Once in the folder type python setup.py build_ext --inplace
  • Note, you may get two errors during this step: if you get an error

    ModuleNotFoundError: No module named 'Cython'

    just type pip install cython, and if you get an error that looks like this

    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    Then you need to follow this link and install the Microsoft Visual C++ package. It will look like this:

    Once you get those errors worked out, go back and run the python setup.py build_ext --inplace command again. Once you run it, look back in the darkflow folder and you should see a new ‘build’ folder in there. That means it worked.

  • Alright, were getting close to the finished product, for real this time, I swear. So since the darkflow repository doesn’t come with the weights, we will have to download then from the YOLO website. So follow this link and scroll down to the weights section. It will look like this:

  • Once you have the weights downloaded, we need to create a new folder inside the darkflow-master folder called ‘bin’, and put the weights in that new folder.

  • Now we just need to get a ‘.mp4’ video to analyze. I just downloaded a random video from youtube using save the video website. Try to get footage that has lots of people and/or cars in it to see YOLO’s full potential. Once you have the video file, you just need to put it in the main darkflow-master folder.
  • Finally, its time to run the program. You will need to type
    python flow --model cfg/yolo.cfg --load bin/yolov2.weights --demo people_walking.mp4 --gpu 1.5 --saveVideo
  • When you run it, a file called video will show up in the darkflow-master folder. Open it up and check it out. The process will take a while depending on how big of a video file you are processing