Cette fois, j'ai essayé d'exécuter YOLO v3 dans l'environnement de Google Colaboratory.
Suivez les étapes pour configurer YOLO v3 sur Google Colaboratory Configuration YOLO Veuillez vous référer au chapitre.
** YOLO ** est un ** système de détection d'objets en temps réel **. Il fait partie d'un cadre de réseau neuronal appelé Darknet. Le mot YOLO est un acronyme pour "Vous ne regardez qu'une seule fois". YOLO v3 est la version 3 de YOLO et est actuellement la dernière version. Pour plus de détails, veuillez vous référer à la page officielle YOLO.
L'environnement utilisé cette fois est Google Colaboratory. Les autres versions sont les suivantes.
import platform
import cv2
print("Python " + platform.python_version())
print("OpenCV " + cv2.__version__)
# Python 3.6.9
# OpenCV 4.1.2
Importez la bibliothèque requise pour afficher l'image.
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib
Maintenant, configurons YOLO v3 sur Google Colab. Nous allons créer un répertoire de travail et y travailler. Notez que cette configuration n'est pas nécessaire après la première (pour cela, travaillez sous le répertoire de travail).
import os
os.mkdir(working_dir) # working_dir est le répertoire de travail
os.chdir(working_dir)
Clonez le darknet.
!git clone https://github.com/pjreddie/darknet
Après le clonage, accédez au répertoire darknet et exécutez make.
os.chdir(working_dir + 'darknet')
!make
Une fois la création terminée, téléchargez le modèle entraîné (poids).
!wget https://pjreddie.com/media/files/yolov3.weights
Ceci termine la configuration de YOLO v3 sur Google Colab.
Maintenant, déplaçons YOLO pour détecter les objets. Utilisez l'image d'exemple déjà préparée. L'image d'exemple est sous darknet / data.
!./darknet detect cfg/yolov3.cfg yolov3.weights 'data/dog.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
#     4 res    1                 304 x 304 x  64   ->   304 x 304 x  64
#     5 conv    128  3 x 3 / 2   304 x 304 x  64   ->   152 x 152 x 128  3.407 BFLOPs
#     6 conv     64  1 x 1 / 1   152 x 152 x 128   ->   152 x 152 x  64  0.379 BFLOPs
#     7 conv    128  3 x 3 / 1   152 x 152 x  64   ->   152 x 152 x 128  3.407 BFLOPs
#     8 res    5                 152 x 152 x 128   ->   152 x 152 x 128
# .........
#    97 upsample            2x    38 x  38 x 128   ->    76 x  76 x 128
#    98 route  97 36
#    99 conv    128  1 x 1 / 1    76 x  76 x 384   ->    76 x  76 x 128  0.568 BFLOPs
#   100 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
#   101 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
#   102 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  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/dog.jpg: Predicted in 22.825540 seconds.
# dog: 100%
# truck: 92%
# bicycle: 99%
La détection d'objet est terminée. Montrons l'image et vérifions-la. L'image qui représente le résultat de la détection d'objet est darknet / predictions.jpg.
img_in = cv2.imread('data/dog.jpg')
img_out = cv2.imread('predictions.jpg')
plt.figure(figsize=[20,10])
plt.subplot(121);plt.imshow(img_in[:,:,::-1]);plt.axis('off')
plt.subplot(122);plt.imshow(img_out[:,:,::-1]);plt.axis('off')

"Chien", "vélo" et "voiture" peuvent être détectés.
Vérifions également d'autres images.
!./darknet detect cfg/yolov3.cfg yolov3.weights 'data/horses.jpg'
img_in = cv2.imread('data/horses.jpg')
img_out = cv2.imread('predictions.jpg')
plt.figure(figsize=[20,10])
plt.subplot(121);plt.imshow(img_in[:,:,::-1]);plt.axis('off')
plt.subplot(122);plt.imshow(img_out[:,:,::-1]);plt.axis('off')

!./darknet detect cfg/yolov3.cfg yolov3.weights 'data/person.jpg'
img_in = cv2.imread('data/person.jpg')
img_out = cv2.imread('predictions.jpg')
plt.figure(figsize=[20,10])
plt.subplot(121);plt.imshow(img_in[:,:,::-1]);plt.axis('off')
plt.subplot(122);plt.imshow(img_out[:,:,::-1]);plt.axis('off')

!./darknet detect cfg/yolov3.cfg yolov3.weights 'data/kite.jpg'
img_in = cv2.imread('data/kite.jpg')
img_out = cv2.imread('predictions.jpg')
plt.figure(figsize=[20,10])
plt.subplot(121);plt.imshow(img_in[:,:,::-1]);plt.axis('off')
plt.subplot(122);plt.imshow(img_out[:,:,::-1]);plt.axis('off')

Cette fois, j'ai essayé d'exécuter YOLO v3 dans l'environnement de Google Colaboratory. La détection d'objets a été effectuée à l'aide des images échantillons déjà préparées. Je pense qu'il serait intéressant de préparer diverses images et de détecter des objets.
Recommended Posts