Object detection with Custom Vision Service

In this post I’ll show you how to train your own model to detect objects in an image.

As many of you know, I am a runner. After I run a race I usually get an email trying to sell me my race photos. This got me thinking about how photographers manage to sort through all the photos.  It’s a great example of leveraging image analysis for a business. You need to find the runner in the photo, locate their bib, and read the number on their bib.

In this post I’ll show you how I was able to use a drag and drop tool to locate the bibs in race photos.

If you want to try it yourself, you need a Microsoft account and an Azure subscription.

Launch the Azure Custom Vision Service.

Custom Vision Service Home Page

Custom Vision Service Home page

Sign in with your Microsoft account, and Create a New Project

Create New Project Custom Vision Service

Create New Project

  • Enter a project name and description.
  • Select the project type to Object Detection
  • Select Create new resource group
Set Project Properties

Set Project Properties

A resource group is like a project folder. Your custom vision service will be stored inside the resource group.

  • Enter a name for your resource group
  • Select your Azure subscription
  • Select a data centre location where you want your resource group stored
  • Select a pricing tier
Create resource group

Create resource group

Select Create resource and then select Create project to create your project.

You will be redirected to the project home page.

You need to upload images to train your model.

Upload images

Upload images

Select Add images and upload at least 15 images containing the object you wish to detect

If you want to try the running bibs example, you can use the images in the zip files in my Analyze Image GitHub \ Object Detection folder. These images were generously provided by some of my running friends.

Once the images are uploaded, you need to tag each image with the object you are training your model to detect. I am going to train my model to identify runners and bibs.

Select the first image you uploaded and it opens in the tagging page

SelectImageToTag

ImageDetail

Once you have your image open, click on the surface and draw a rectangle around the object you want to detect and then provide a tag to identify that object.

I have drawn a box around the runner in the middle of the photo and their bib and tagged them as runner and bib.

I repeat the same process for the other runners in the picture and for their bibs if they are visible

SecondRunner

When you are done you can close the window and open the next photo for tagging, or you can just select the arrow key to the far right of the Image detail to scroll to the next image to tag.

FinishedTagging

Complete this process for each of your training images.

Now select Train from the top menu bar to train your model.

TRainModel

Select a Training Type

Fast training is great for proof of concept situations like this one. Advanced training allows you to increase the training time (which will consume more cloud credits) and will notify you when training is completed.

TRainingType

 

Once training is complete you will see your iteration statistics and you can test it using Quick Test

QuickTest

Select Browse local files or provide a URL to an image containing the object you want to detect. The trained model will attempt to identify the regions containing the images and provide a probability/confidence level for each.Results

My model has successfully identified multiple runners in the photo and the location of the race bib.

The trained model can now be called from code to retrieve the predictions as JSON.  I have an example of how to call a classification model created with this tool in my GitHub.

 

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: