Custom Object detection using ImageAi with few steps

Bernardo Caldas
Analytics Vidhya
Published in
3 min readJun 15, 2020

--

ImageAI is a python library built to empower developers, reseachers and students to build applications and systems with self-contained Deep Learning and Computer Vision capabilities using simple and few lines of code” Official documentation ( https://imageai.readthedocs.io/en/latest/)

ImageAi is a very powerful tool to create models for custom dataset, practical and easy to use, follow those steps to create your own classifier;

1- prepare your dataset

2- Install imageAi

3- Download pre trained weights ( yolo, RetinaNet )

sample object detection

Computer Vision

In recent years we can see a lot applications in our life including, autonomous cars, facial detections app, education, military, finance etc.

sample object segmentation
sample object detection

Prepare the dataset

It is necessary to collect a good number of images for the training process, it is recommended for the project at least 200 images for each class, below follows the structure;

Annotating images

ImageAi supports the Pascal Voc annotation format, personally to annotate images I used LabelIMG, an easy to use tool, after the separation seen above the project structure, between training and validation (70% training images and 30% validation images). open LabelImg and we start the process of annotating images as shown below, for each image in the dataset.

after annotating each image the application will generate an xml file for each image that should be directed to the “annotations” folder,

Installing ImageAi and training requirements

As already described we use Google Colab to perform the training using enabling the GPU to speed up the process;

Requirements

Python : https://python.org

Tensorflow : !pip3 install tensorflow ( Versão inferior a 2.0 )

OpenCV : !pip3 install opencv-python

Keras : !pip3 install keras

ImageAI : !pip3 install imageai — upgrade

Download pre model yolov3

!wget https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5

After executing the previous steps and enabling the notebook’s GPU on google colab we can train our application, for that we must run the code below, the complete project documentation is very well written and easy to understand,

link: https://imageai.readthedocs.io/en/latest/customdetection/index.html

Now just wait for the training process … ( about 3 hours )

After the end of the training process, we upload a video to test the application using the code below;

sample for test video object detection

Follow the results;

--

--

Bernardo Caldas
Analytics Vidhya

Developer | AI | Driving innovation with development tools and AI. Making technology meaningful