Now we are doing very interesting things. You are going to build your own Object Detection model. Open your Google Drive and create a new Colab notebook so we can get started. There are two steps to make in this lesson.
Mount your drive
Install YOLO and dependencies
Tähän video, tarvitsee testvideomp4.yaml edukamu-komponentin, jos käytetään videoita mp4:na, pelkkä url kansioon ei tunnista videoformaattia
Firstly, we need to run the following command.
from google.colab import drive
drive.mount('/content/gdrive')
Click the link that pops up, and then follow the instructions to get an authorization code. You can simply copy the code and paste it down. Doing this will mount the drive for you.
Click the link, and then follow the instructions to get an authorization code. You can simply copy the code and paste it down. Doing this will mount the drive for you. Keep in mind that the authorization code shouldn’t be shared with anyone.
Then go to the "Runtime" menu and change your hardware accelerator setting to GPU. See the video below for instructions.
Tähän video, tarvitsee testvideomp4.yaml edukamu-komponentin, jos käytetään videoita mp4:na, pelkkä url kansioon ei tunnista videoformaattia
!nvidia-smi
The following steps are quite simple, clone the darknet repository and add a path for cuda. Cuda is a parallel computing platform created by Nvidia.
#clone darknet repository
import os
os.environ['PATH'] += ':/usr/local/cuda/bin'
!rm -fr darknet
!git clone https://github.com/AlexeyAB/darknet/
We also install gcc-5 and g++-5. They are compilers that we will be using for the video.
!apt install gcc-5 g++-5 -y
!ln -s /usr/bin/gcc-5 /usr/local/cuda/bin/gcc
!ln -s /usr/bin/g++-5 /usr/local/cuda/bin/g++
Proceed by going to the "darknet" folder and enable GPU and OpenCV support. OpenCV is a library of programming functions mainly aimed at real-time computer vision. We use it in combination with "weights".
cd darknet
!sed -i ‘s/GPU=0/GPU=1/g’ Makefile
!sed -i ‘s/OPENCV=0/OPENCV=1/g’ Makefile
!make
Get the yolov3 weights. Weights are a pre-trained model that is used to "see" things in the video. Yolov3 weights are a great balance between accuracy and speed. We also make a darknet executable.
# get yolov3 weights
!wget https://pjreddie.com/media/files/yolov3.weights
!chmod a+x ./darknet
Check content location:
!pwd
Install mandatory python and opencv libraries with this code:
!apt install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
!apt install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
After doing all of this, we can move on to the next lesson, which will be uploading a video and getting some concrete results with YOLO.