So far, I've tried techniques such as BING, Selective Search, and Faster-RCNN for object detection. This time, I would like to try YOLO (v2), which is probably the fastest at the moment (June 2017). The original is written in C language. https://pjreddie.com/darknet/yolo/ ・ Click here for past articles I tried using BING with OpenCV as pre-processing for CNN I tried using Selective search as R-CNN Let's detect real-time objects using Faster R-CNN
OS: Ubuntu16.04LTS GPU:GTX-1050 Python:3.5 CUDA8.0 cuDNN5.1
Thankfully, the version using TensorFlow has been released, so this time I will use here. (I also made a wrapper class in C ++, but I want to use Python) The installation is exactly as described in the Readme, so I don't think you'll stumble. (* If you have not installed TensorFlow and OpenCV, please install them in advance.)
Clone from GitHub and put it in a folder.
git clone https://github.com/thtrieu/darkflow.git
cd darkflow
Download the weight file from the YOLO homepage.
wget https://pjreddie.com/media/files/yolo.weights
There are three installation methods as follows. Let's install it according to your environment.
■ Method 1 (: If you install this way, you need to use ./flow in the duplicated dark flow directory instead of the flow because it is not installed globally.)
python3 setup.py build_ext --inplace
■ Method 2 (Install globally using pip. Globally accessible, but code changes take effect immediately)
pip install -e .
■ Method 3 (Install globally using pip)
pip install .
There is nothing particularly difficult.
bin / yolo.weights
will contain the path of the weight file you downloaded earlier.
The result result
stores the result in JSON format. After that, parse this and draw.
Gpu: 1.0
is the GPU usage rate. In my environment, when I set it to 1.0, I got an Out Of Memory error, so I set it to 0.6.from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1, "gpu": 1.0}
tfnet = TFNet(options)
imgcv = cv2.imread("./sample_img/dog.jpg ")
result = tfnet.return_predict(imgcv)
print(result)
I used TensorFlow this time, Other versions of Keras, Chainer, etc. have been uploaded to GitHub. Try YOLO (v2) with your favorite framework. Keras version Chianer version However, I am very grateful that the latest methods can be easily tried with various frameworks. I also want to provide a useful source for people these days.
Recommended Posts