Where's Chewie? Object detection with Azure Custom Vision
Tags: azure, ai, customvision, computervision
Published: 2020-05-03 21:33:16

["Where's Waldo?"](https://en.wikipedia.org/wiki/Where%27s_Wally%3F) game is very well known by everyone, in this post I'll explain how to make such game with Azure Custom Vision and LEGO minifigures. This was my weekend project, feel free to recreate it and while learning how Azure Custom Vision works you can also entertain your child to help you out with it.

I'll be using [Chewbacca](https://en.wikipedia.org/wiki/Chewbacca) LEGO minifigure (nicknamed **Chewie**) that AI should detect in image among other minifigures.

![Chewbacca LEGO minifigure](https://dev-to-uploads.s3.amazonaws.com/i/u0ui1i42ka23nd45ux7k.png)

Board where Chewbacca will be hiding can be seen on the following image, it consist of 49 different LEGO minifigures.

![LEGO board with minifigures](https://dev-to-uploads.s3.amazonaws.com/i/m9aje3pxzmia1qntm8hi.jpg)

In order to follow next steps you should have an Azure account, if you don't have one you can create it [here](https://azure.microsoft.com/en-us/free/).

When you sign in with your Azure account into Custom Vision ([www.customvision.ai](https://www.customvision.ai/)) you'll see a page that shows your projects.

![Custom Vision projects](https://dev-to-uploads.s3.amazonaws.com/i/ay7mut6rb8yziw1zej8s.jpg)

Clicking on "New project" will ask you to enter projects name, you can add description and you need to select [resource](https://docs.microsoft.com/en-us/azure/cloud-adoption-framework/govern/resource-consistency/resource-access-management#what-is-an-azure-resource).

![Create new project](https://dev-to-uploads.s3.amazonaws.com/i/mltk678jms29hsnq5oeh.jpg)

If you are creating a new resource, you should define resource name, subscription, resource group, what kind of resource is that (CognitiveServices), location and pricing tier.

![New resource](https://dev-to-uploads.s3.amazonaws.com/i/rq5qmtl28su7yd89zdvy.jpg)

For new resource group you should just define name and location.

![New resource group](https://dev-to-uploads.s3.amazonaws.com/i/k9qpd43nq5s7fp2bg08o.jpg)

After you fill this in you can select type and domain for your new project.

Image classification is used when you want to classify the whole image, which object is represented the most in the image. Object detection is used to find location of content in the image and this is what we need for this project.

For domain we'll use General domain which is explained by Microsoft as "Optimised for a broad range of object detection tasks. If none of the other domains are appropriate, or you are unsure of which domain to choose, select the Generic domain". Feel free to read more about the domains [here](https://docs.microsoft.com/en-us/azure/cognitive-services/custom-vision-service/select-domain).

![Create new project](https://dev-to-uploads.s3.amazonaws.com/i/s0cgg70rpyb8rqzba63i.jpg)

Once project is created you'll be able to see project page that is currently empty and gives you option to upload images to train your model.

![Project page](https://dev-to-uploads.s3.amazonaws.com/i/3x2lykkcj8yxq2fwsysd.jpg)

I took several images of the LEGO Chewbacca minifigure from different angles. I also made a little trick, as you can see on the images below, I've placed minifigure on top of the LEGO catalogue and I switched pages for each image. That way model will be able to distinguish better what is minifigure and what is background in the image.

![Image upload](https://dev-to-uploads.s3.amazonaws.com/i/6j4v1jcrmfdllzl9kucg.jpg)

When images are uploaded you can manually tag them. UX is really nice here and you'll notice that tagging tool will suggest a frame around objects it detects. For first tag you'll need to enter a name, afterwards you can select it for other images. Adjusting frame to fit the minifigure is super easy.

![Tagging images](https://dev-to-uploads.s3.amazonaws.com/i/5wlfa8r8yow2l4bg2hj9.jpg)

We prepared the images and we can now start the training, in this case quick training. Advanced training should be used on advanced and challenging datasets.

![Training](https://dev-to-uploads.s3.amazonaws.com/i/hwxuxiu0aq3ucalebx4x.jpg)

When training is finished you'll see information about it:
 - Precision: this number will tell you: if a tag is predicted by your model, how likely is that to be right
 - Recall: this number will tell you: out of the tags which should be predicted correctly, what percentage did your model correctly find
 - mAP: mean average precision will tell you: the overall object detector performance across all the tags

![Quick test](https://dev-to-uploads.s3.amazonaws.com/i/4s1v39upyehtl75u14ip.jpg)

Quick test I made with the image of the whole board showed me that some objects were identified as target minifigure but with really low precision (20%). Dataset I made was really small number of images, so I was not surprised and I expected to see something like this.

![Quick test](https://dev-to-uploads.s3.amazonaws.com/i/uq5gbjb9d7bvcz69mnlw.jpg)

Predictions allows you to see images that were used for prediction and here you can go into images and correctly tag them.

![Predictions](https://dev-to-uploads.s3.amazonaws.com/i/vk6zkrttv590j8bdwpt0.jpg)

I fixed predictions several times and added much more images in my dataset. Once everything is in place this is quick and simple to do. After few iterations of my model I tried with new image (that Custom Vision model haven't seen yet) and it successfully found the Chewie with accuracy 40.8%!

![Quick test](https://dev-to-uploads.s3.amazonaws.com/i/tznn6fvh4dxsfermr4hs.jpg)

Accuracy of the model can be improved further with adding more images to the data set, by using advanced training, etc. In my case I was happy with the result since this is what I aimed for: "Where's Waldo"-like game.

Thanks for reading!