Custom Vision Lab
In this lab, we will learn how to recognize different objects in the image using Microsoft Custom Vision API.
Come up with a Problem
You can train Custom Vision API to recognize different objects in a picure by using relatively small training dataset (10-50 images). However, it can only be used in cases when the object is quite clearly visible, and occupies most of the picture. For more complex object detection scenarious and for object localizaton, you need to use more complex techniques based on neural networks.
Keeping this consideration in mind, try to come up with a problem for object recognition. You shoud be able to find 20-30 similar images of each object category in Bing Image Search (or otherwise have those training images available).
Good examples of problems can be:
- Recognizing different soda types: Fanta, Cola, Sprite
- Recognizing logos of different brands: Microsoft, Intel, Google
- Recognizing type of goods in the supermarket
- Recognizing different electronic components
- Recognizing animals
Getting training images
One of the ways to get training images is to use Bing Image Search. To automatically download top Bing Image Search results, you can use the imdownload.exe utility provided. Download the ZIP file and unpack it somewhere. You can call it from the command line in the following way:
imdownload <bing key> "<search term>" [<image mask with #> <number of images>]
You need Bing Search API key to use it - please obtain your own key here
or through your cloud subscription (by creating Cognitive Services -> Search object). You can also try to use the following key, but just for the sake of this lab:
For example, to download 30 pictures of yellow cats, use the command:
imdownload xxxxxx "Yellow Cat" Cat# 30
After downloading images for each category, you need to clean up the training data:
- browse all images and delete those that do not correctly repserent the category
- put some of the images (2-5) aside, to be used as testing data
Train the Model
To create and train the model, go to http://customvision.ai and do the following:
- Select New Project and fill in project name, etc.
- For each category, upload training images and assign them to a certain tag which represents category
- Select Train Model and observe the values of precision and recall. Those values reflect the accuracy of the model (the bigger the numbers - the better), and allow estimating percentage of false positive and false negative errors.
- For testing the model, select Quick Test and upload testing images (which we have set aside earlier).
Testing Model through Telegram Bot
To test your model, add
@MyCustomVisionBot as a new user in Telegram.
In order to use your model, you need to provide the bot with your model id and prediction key. In the control panel of Custom Vision service, select
Performance -> Prediction Url. Look for the following informtion:
- Service URL, which will look like this:
- Prediction Key (alphanumeric sequence)
First of all, send to the bot your model id (characters
xxxxxx-xxxx-xxxx-xxxx-xxxxx in the URL above) and prediction key, separated by space.
After your bot has been given model id and prediction key, you can send it images to recogize. It is very convenient way to test a model against images that you take with your phone camera.
I hope you have enjoyed the exercise!