Join thousands of AI enthusiasts and experts at the Learn AI Community.

Publication

Computer Vision

Car and Pool Detector Using Monk AI

Last Updated on August 29, 2020 by Editorial Team

Author(s): Omkar Tupe

Photo by Kelly Lacy from Pexels

Computer Vision

About the project

This project is focused on detecting cars and pools from satellite images using CornerNet[1]. Performing object detection, by coding from scratch, can be difficult and tedious for someone not very well acquainted with the field. With Monk AI this can be done in a seemingly easier way. Using Monk AI [2], one can accomplish various computer vision tasks like object detection with very few lines of code. This project can help gain a better understanding of the MonkAI toolkit. Through this blog, I will share some insights about MonkAI, and how it can be used to simplify the process of object detection and build other computer vision applications.

Tutorial available on GitHub.

Cars and pools detection(Images are taken from Kaggle dataset)

Features of Monk AI

  • A low code programming environment.
  • Using MonkAI one can access PyTorch, MXNet, Keras, TensorFlow, etc. with a common syntax.
  • For Competition and Hackathon participants: The hassle-free setup makes prototyping faster and easier

The Dataset

For this project, Satellite images are used for training the model to detect cars and pools. Annotations are stored in VOC format. The dataset has 3748 train images and 2703 test images. The dataset is available on Kaggle.

CornerNet

CornerNet, a new approach to object detection where one can detect an object bounding box as a pair of key points, the top-left corner, and the bottom-right corner, using a single convolution neural network. By detecting objects as paired key points, it is possible to eliminate the need for designing a set of anchor boxes that were previously used commonly in single-stage detectors.

Don’t worry about architecture MONK will take care of this(Image Ref-https://arxiv.org/abs/1808.01244)

Table of contents

  1. Installation instructions
  2. Use an already trained model
  3. Train a custom detector

— Annotations conversion (VOC to COCO via MONK)

— Training

4. Inference model

1. Installation instructions

Here we are using Google Colab for training as it provides CUDA GPU. But one can use a local device or Kaggle notebook. Now we will setup MonkAI toolkit and dependencies on the colab.

https://medium.com/media/67d9e187c5e85d5123d4bc269dca2f4f/href

2. Use an already trained model

Monk helps to understand the detection results using a pre-trained model to demonstrate our application.

Downloading the pre-trained model.

https://medium.com/media/0b1f3907449ccfce333980c057432f8d/href

Unzip the folder

https://medium.com/media/5c72ca227634089ed9532d463c19dc24/href

The obj_satellite_car_pool_trained folder will have the pre-trained model file and some test images.

Setting up a detector

https://medium.com/media/05d88e1beae099ced5f08124605b87dc/href

From a given folder, we are using a weight file (obj_satellite_car_pool_trained/CornerNet_Saccade_final-1000.pkl)

https://medium.com/media/66348174e9e0f69e77e7f7312cde978b/href

From the unzipped folder, we are using some images for inference purposes.

Inference-1

https://medium.com/media/c644d6aa34f32f4cf30d7f27694eb198/href

Inference-2

https://medium.com/media/8448960086aad2708cf76c21200437f9/href

3. Train a custom detector

We are using a dataset from Kaggle so we have to install Kaggle API on colab.

Please follow the steps below to download and use Kaggle data within Google Colab[4]:

  1. Go to your account, Scroll to API section and Click Expire API Token to remove previous tokens
  2. Click on Create New API Token — It will download the kaggle.json file on your machine.
  3. Go to your Google Colab project file and run the following commands:

https://medium.com/media/6841bac5281f837f5c1ebfc5a9f9b4f8/href

Time to download your dataset

Go to the dataset you want to download on Kaggle and copy the API command which Kaggle provides. That should look like the following:

https://medium.com/media/fa90cf97cd310f2b6a5d8518082e0d9f/href

To train a model using Cornernet-Saccade, the annotation should be in the COCO format, but we have the annotation in VOC format. Hence, we need to convert VOC format to COCO format via MONK format. You can find detailed code about this on Github

VOC format(Dataset directory structure)

https://medium.com/media/e260bfa678f2ef7d9f08db3a02291611/href

Monk format

https://medium.com/media/0fda6dc66465f9a64f9f2002fc2b6881/href

COCO format(Desired annotations)

https://medium.com/media/77a3e2bc40af32f9d528c49d63a5672e/href

Annotation Conversion

You can find detailed code about this on Github

Training

Using Monk AI we can build concurrent pipeline, we can do model selection and it is easy to set hyperparameters

  1. Importing dependencies
  2. Set detector path
  3. Set dataset and annotation path
  4. Select model (here we are using CornerNet_Saccade)
  5. Set hyperparameters(learning rate as 0.00025,total iterations 10000)

https://medium.com/media/981d84df0ed43fcc9bc8a377dcd590fe/href

6. Now complete setup for training. Here we are loading annotations in memory followed by index creation and loading model.

https://medium.com/media/a8dd568be21a33a80919d5eb0b60a4c1/href

7. Now we will start our training as

https://medium.com/media/080b445eb00d43cd8db81462649224c2/href

Now here we can see all hyperparameters settings. The total number of available parameters for training is 116849063. It is always best practice that we should shuffle data during each iteration so we are shuffling dataset’s indices.

Weights file will be stored in ‘cache/nnet/CornerNet_Saccade/’ as intermediate as well as the final file.

4.Inference

It will be similar to the pre-trained model but now we will use our own trained model so the model path will be different.

  1. Set detector path
  2. Define classes.

https://medium.com/media/f05d9473b3236e835d87e9b5e6cd3ede/href

3. Set the trained model path.

https://medium.com/media/f13e1c20f6818e66b886d8d2e918fa87/href

4. Provide some test images for testing.

Test image-1

https://medium.com/media/716bca9548eaaed28a792e7a1e2d34ed/href

Test image-2

https://medium.com/media/489c471524ff8ea90f3c363cf623c144/href

From multiple trial and error threshold is set as 0.3

For threshold value, less than 0.3 multiple detector boxes are observed and for threshold value greater than 0.3 it is difficult for a detector to detect car.

As we used satellite images the size of the car is much less than the pool in terms of pixels. More features are available for pools

Conclusion

To conclude, our task was done in very few lines of code. We have demonstrated only one pipeline in this article, but Monk AI has a total of seven such pipelines from GluonCV to YOLOv3. All in all, Monk AI is a great library that makes working with such computer vision tasks pretty easy.

All the code shown in this article resides in this colab notebook.

You can find many more examples of detection and segmentation in the application model zoo.

Thanks for Reading! I hope you find this article informative & useful. Do share your feedback in the comments section!

References

  1. CornerNet-https://arxiv.org/abs/1808.01244
  2. Monk AI- https://github.com/Tessellate-Imaging/Monk_Object_Detection
  3. Kaggle dataset- https://www.kaggle.com/kbhartiya83/swimming-pool-and-car-detection
  4. Downloading Kaggle dataset on Google colab- https://www.kaggle.com/general/74235


Car and Pool Detector Using Monk AI was originally published in Towards AI — Multidisciplinary Science Journal on Medium, where people are continuing the conversation by highlighting and responding to this story.

Published via Towards AI

Feedback ↓