Using YOLOv3 Model in Python with ImageAI Library

Before you start to read the tutorial, you should have the basic understanding of YOLOv3. If you don’t, you can check my previous articles to know the concept.

Python影像辨識筆記(九):分別在Windows和Ubuntu 18.04上安裝並執行YOLOv3(使用GPU)Python影像辨識筆記(九之二):關於YOLOv3的一些心得Python影像辨識筆記(九之三):YOLOv3結合深度學習的Object DetectorPython影像辨識筆記(九之四):可視化YOLOv3訓練過程中的loss、IOU、avg Recall等的曲線圖Python影像辨識筆記(九之五):透過Google Colab在雲端運行YOLOv3Python影像辨識筆記(九之六):將LabelImg標記的xml檔案轉成txt檔案NVIDIA Jetson TX2學習筆記(三):執行YOLOv3The Complete YOLOv3 Reproduce List on GitHubUsing YOLOv3 Model in Python with ImageAI Library

According to the GitHub repo, ImageAI is an open-source python library built to empower developers to build applications and systems with self-contained Deep Learning and Computer Vision capabilities using simple and few lines of code.

Lasy year my team participated in a competition, we used YOLOv3 as our Object Detection model to detect endangered bird “Pheasant-tailed Jacana”. We got special prize finally in November 20. We were all happy about that, but we still want to improve the project.

This time we would try to detect the most visited bird species in Taiwan. It seems pretty interesting but also hard. And frankly speaking our model was based on Darknet, the performance was’t good enough to become a final product.

So I try to figure out the way to improve the detection speed.

Let’s take a look at this markdown page below:

This project use *.h5 (keras model) as the input model file. If you have a pretrained YOLOv3 weights, you must convert it to *.h5 file type so that ImageAI can support it.

FirstObjectDetection.py

from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()detector = ObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "image2.jpg"), output_image_path=os.path.join(execution_path , "image2new.jpg"), minimum_percentage_probability=30)
for eachObject in detections:
print(eachObject["name"] , " : ", eachObject["percentage_probability"], " : ", eachObject["box_points"] )
print("--------------------------------")

For more example and usage please check the original documentation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store