Try real-time object recognition using YOLOv2 (TensorFlow)

Introduction

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

Execution environment

OS: Ubuntu16.04LTS GPU:GTX-1050 Python:3.5 CUDA8.0 cuDNN5.1

Preparation

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 .

Sample code

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.

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)

result

sample1.png

Summary

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

Try real-time object recognition using YOLOv2 (TensorFlow)
Let's try real-time object detection using Faster R-CNN
Logo detection using TensorFlow Object Detection API
Try using GCP Handwriting Recognition (OCR)
Circular object recognition using Hough transform
Try using Bash on Windows 10 2 (TensorFlow installation)
Object detection using Jetson Nano (YOLOv3)-(1) Jetson Nano settings-
Try using Tkinter
Try using docker-py
Nogizaka recognition program (using Yolov5) Table of contents
Try Distributed TensorFlow
Try using cookiecutter
Try using PDFMiner
Try using geopandas
Try using Selenium
Try using pandas.DataFrame
Try using tensorflow ① Build python environment and introduce tensorflow
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try using PyODE
Try using virtualenv (virtualenvwrapper)
[Azure] Try using Azure Functions
Try using virtualenv now
Try using W & B
Try using Django templates.html
[Kaggle] Try using LGBM
Try using Python's feedparser.
Try using Python's Tkinter
TensorFlow Tutorial-Image Recognition (Translation)
Try regression with TensorFlow
Try using Tweepy [Python2.7]
Try using Pytorch's collate_fn
2020/02 Python 3.7 + TensorFlow 2.1 + Keras 2.3.1 + YOLOv3 Object detection with the latest version
General object detection using Google's pre-trained model (via TensorFlow Hub)
Real-time image recognition on mobile devices with TensorFlow learning model
Real-time object detection Android app with TensorFlow and Camera X
[For beginners] I tried using the Tensorflow Object Detection API