Detect any custom object with DeepStack

Moses Olafenwa
DeepQuestAI
Published in
5 min readJan 31, 2021

This tutorial details how to create APIs for detecting and recognizing any custom object using DeepStack AI Server

Computer vision has made it possible to develop applications and automation systems that have the ability to detect, identify and locate objects in images, videos and live camera feeds. With profound impact on many areas of socio-economic activity such security, manufacturing, quality assurance, IoT, autonomous vehicles e.t.c , today’s computer vision powered by deep learning models provide limitless opportunity to develop highly intelligent visual systems.

For most developers, researchers and IT engineers, the primary sources for state-of-the-art computer vision integrations are:

  • DNN models
  • Vision APIs from cloud services

Most computer vision APIs and machine learning models are built to recognize and detect commons objects like persons, electronics, animals, etc. While these does suffice for a lot of computer vision applications, majority of visual tasks involve detection and recognition of custom objects.

E.g detecting defects in a new products, identifying and counting different products in a supermarket store, detecting plant diseases, etc.

In this article, we are going to show you how you can create a computer vision API to detect any object or set of objects for your research, industrial and automation needs using DeepStack.

What is DeepStack?

DeepStack is an open-source AI API server that empowers every developer in the world to easily build state-of-the-art AI systems both on premise and in the cloud. DeepStack is device and programming language agnostic. You can run it on Windows, Mac OS, Linux, Raspberry PI and NVIDIA Jetson devices. The following are features in-built into DeepStack

  • Face detection, matching and recognition APIs
  • Common objects detection and recognition APIs
  • Scene recognition APIs
  • Custom objects detection APIs
  • API security

For the purpose of this tutorial, we will be using a custom DeepStack model that has been trained to detect and recognize all the 352 commons logos in the OpenLogo dataset. Follow the steps detailed below:

  • Prepare your dataset
  • Train your custom DeepStack Model
  • Deploy model to create your API

Step 1 — Prepare your dataset

The first step is to collect a minimum of 350 images of the object you are want to detect ( 300 for train and 50 for validation/testing). You can also use an existing public image dataset as far as it has the object you intend to detect and recognize. For the purpose of this tutorial, we have collected and prepared the OpenLogo dataset and ready for you to use. You can download this dataset via the link below

https://deepquest.sfo2.digitaloceanspaces.com/deepstack/zeus/logo_dataset.zip

To prepare your own dataset, use the guide in the DeepStack documentation link provided below

Step 2— Train your custom DeepStack Model

The next step is to train a DeepStack model on your custom dataset. DeepStack currently uses the YOLOv5 deep neural network architecture for deploying custom models. For the purpose of this tutorial, we have provided a pre-trained DeepStack model for detecting all the 352 commons logos in the Open Logo dataset. You can download the model file openlogo.pt in the link below

To train your custom model, use the guide in the DeepStack documentation link below. This guide provides

  • end-to-end code and guide for training and generating your custom model
  • link to a free Nvidia GPU on the cloud to train your model

Step 3— Deploy model to create your API

Once you have your model file ( .pt file ), take the following steps to create your detection API to detect your custom object(s). In the case of this tutorial, we will create an API to detect logos. Follow the steps below:

  • Install DeepStack on your machine: Install DeepStack AI Server with instructions on DeepStack’s documentation via https://docs.deepstack.cc
  • Keep model in a folder: Create a folder on your machine and put the .pt model file into it ( e.g openlogo.pt )
  • Run DeepStack to create API: To run DeepStack AI Server with the custom model, run the command that applies to your machine as detailed below as detailed in this DeepStack documentation link here
    E.g
    For Windows 10
deepstack — MODELSTORE-DETECTION 'C\Users\MyUser\Documents\DeepStack-Models' — PORT 80

For Docker on Linux

sudo docker run -v /home/MyUser/Documents/DeepStack-Models:/modelstore/detection -p 80:5000 deepquestai/deepstack
  • Once you run the DeepStack start command, you will see a terminal/console log like the one below
  • Now your custom logo detection API is active via the endpoint enpoint http://localhost:80/v1/vision/custom/openlogo or http://your_machine_ip:80/v1/vision/custom/openlogo
  • You can now send a POST request to the endpoint from any application using any programming language with the parameter imageset to your image data/file. For this article, we have provided a sample image and python code that uses the DeepStack Python SDK to detect logo in an image.
  • Install DeepStack Python SDK via the command below
pip install deepstack-sdk --upgrade
  • Then run the code below
  • Once you run the code and send request to the openlogo endpoints, you will get the results below from DeepStack.

And a new image with name fedex_new.jpg will be saved with the detected logo visualized as seen below.

  • DeepStack Python SDK makes it easier for you to detect objects in images and video using DeepStack from in your Python code and applications. Visit the DeepStack Python SDK repository linked below for more code examples.

--

--

Moses Olafenwa
DeepQuestAI

Software Engineer @BabylonHealth, Prev. @Microsoft. A self-Taught computer programmer, Deep Learning, AI Engineer.