As the name implies, YOLO (You Only Look Once) is an epoch-making algorithm that recognizes and detects an object just by looking at it once like a human being. Compared to the conventional method, it has the features of high speed processing, strong distinction between object and background recognition, and easy generalization. This time, we will use YOLO and python to detect objects on the photograph where objects are detected using Tiny YOLO and R in the teaching materials.
[High School Information Department "Information II" Teacher Training Materials (Main Volume): Ministry of Education, Culture, Sports, Science and Technology](https://www.mext.go.jp/a_menu/shotou/zyouhou/detail/mext_00742.html "High School Information Department "Information II" teaching materials for teacher training (main part): Ministry of Education, Culture, Sports, Science and Technology ") Chapter 3 Information and Data Science Second Half (PDF: 7.6MB)")
Learning 18 Text mining and image recognition: "3. Object detection using TinyYOLO"
This time, clone (copy) darknet from the repository of github and perform image recognition using the trained weight data yolov3.weights of YOLOv3. This time it is written as an implementation example in python, but in order to run YOLOv3 on darknet, I would like to focus on command execution so that I can detect objects in a way that I do not code by myself as much as possible.
!git clone https://github.com/pjreddie/darknet
The execution result is as follows
Cloning into 'darknet'...
remote: Enumerating objects: 5913, done.
remote: Total 5913 (delta 0), reused 0 (delta 0), pack-reused 5913
Receiving objects: 100% (5913/5913), 6.34 MiB | 9.93 MiB/s, done.
Resolving deltas: 100% (3918/3918), done.
Now that you have a git clone, move to the darknet directory and run make.
import os
os.chdir('darknet')
!make
After the make is completed, download the trained weight data yolov3.weights of YOLOv3 to the same directory. This time I used the wget command.
!wget https://pjreddie.com/media/files/yolov3.weights
I would like to have YOLO detect the object in the main subject, but this time I would like to use giraffe.jpg in the data directory to detect the object.
!./darknet detect cfg/yolov3.cfg yolov3.weights data/giraffe.jpg
layer filters size input output
0 conv 32 3 x 3 / 1 608 x 608 x 3 -> 608 x 608 x 32 0.639 BFLOPs
1 conv 64 3 x 3 / 2 608 x 608 x 32 -> 304 x 304 x 64 3.407 BFLOPs
2 conv 32 1 x 1 / 1 304 x 304 x 64 -> 304 x 304 x 32 0.379 BFLOPs
3 conv 64 3 x 3 / 1 304 x 304 x 32 -> 304 x 304 x 64 3.407 BFLOPs
:
103 conv 128 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 128 0.379 BFLOPs
104 conv 256 3 x 3 / 1 76 x 76 x 128 -> 76 x 76 x 256 3.407 BFLOPs
105 conv 255 1 x 1 / 1 76 x 76 x 256 -> 76 x 76 x 255 0.754 BFLOPs
106 yolo
Loading weights from yolov3.weights...Done!
data/giraffe.jpg: Predicted in 19.677707 seconds.
giraffe: 98%
zebra: 98%
Giraffes and zebras were detected. Let's take a look at the actual detected image.
from IPython.display import Image
Image("predictions.jpg ")
I was able to detect it successfully.
https://gist.github.com/ereyester/46a25e70c866c581320a66a77153aa2d
Recommended Posts