Watson Visual Recognition — Custom Models
Tags: raspberrypi, machinelearning, ibmwatson, ibm
Published: 2019-02-08 19:13:59

---
title: Watson Visual Recognition — Custom Models
published: true
tags: raspberry-pi,machine-learning,watson,ibm
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/1024/1*Za2J-XXjPUPcsXdQ9DNWKA.jpeg)

Recognizing objects and patterns in images and video used to be a complicated task that was only available to Data Scientists and Software Engineers familiar with Machine Learning. The barrier to entry in this field has drastically reduced in the last few years due to advances in open source libraries and availability of vast amounts of data. IBM particularly has made it very simple to detect objects in images with their Watson Visual Recognition service as we will see in this post.

Here is [quick video](https://youtu.be/7gVVJnNZw5o) if you want to follow along instead of reading this blog.

{% youtube 7gVVJnNZw5o %}

They offer a couple of in-built models

1. **General model**  — Default classification from thousands of classes

2. **Face model**  — Facial analysis with age and gender

3. **Explicit model**  — Whether an image is inappropriate for general use

4. **Food model**  — Specifically for images of food items

5. **Text model**  — Text extraction from natural scene images

Additionally, they offer a very intuitive interface to build and train custom models. You only need a few things to get started.

- IBM Cloud account to log into the Watson Dataplatform
- At least two categories for classification with at least 10 positive images for each category.
- It is advisable to have negative samples as well that do not belong to any of the other target categories.

#### Step by step instructions to train a custom model

Watson Visual Recognition service has a [[API Explorer site](https://watson-api-explorer.ng.bluemix.net/apis/visual-recognition-v3)](https://watson-api-explorer.ng.bluemix.net/apis/visual-recognition-v3) that can be used to analyze images. I gave it a [[raspberry pi image](https://www.raspberrypi.org/app/uploads/2017/05/Raspberry-Pi-Model-B-1-462x322.jpg)](https://www.raspberrypi.org/app/uploads/2017/05/Raspberry-Pi-Model-B-1-462x322.jpg) and it came back with the following keywords.

![](https://cdn-images-1.medium.com/max/462/1*9cvwKx2mLgyu9cvaadRnpg.jpeg)

<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79f1b680fc50e681fa073aff337a5db9/href">https://medium.com/media/79f1b680fc50e681fa073aff337a5db9/href</a></iframe>

The results are not bad at all. The picture is identified as a electrical circuit with a high confidence.

> **electrical device — 0.905**

> **computer circuit — 0.904**

Those categories are correct in themselves, **_but we want to be able to differentiate between the different types of Raspberry Pi boards._**

#### Step by step instructions on create a custom model that can differentiate between different Raspberry Pi boards.

**Step 1 — Log into Watson Data Platform**

![](https://cdn-images-1.medium.com/max/1024/1*i1XB0gA_V6FV1BAaQObLcg.jpeg)

Once you log in, you will be greeted by the main dashboard with helpful hints.

![](https://cdn-images-1.medium.com/max/1024/1*gk24ksNrk3crIFWHJrEAiA.jpeg)

**Step 2 — Create a new _Visual Recognition_ project**

![](https://cdn-images-1.medium.com/max/670/1*KngY8UkDzP315z8lMNAuLQ.jpeg)

![](https://cdn-images-1.medium.com/max/995/1*h5so7n-Ey_FtMExdSVwtcw.jpeg)

**Step 3 — You are shown the custom model screen**

![](https://cdn-images-1.medium.com/max/1024/1*uISX_XFHXHo7P804Nxxt2g.jpeg)

**Step 4 — Organize training images into correct folders**

I download a dozen images of Raspberry Pi Model A Plus and Raspberry Pi Model B Plus board each. Additionally, I downloaded a few negative images (boards that are neither). The folder structure should look like:

![](https://cdn-images-1.medium.com/max/664/1*eMRf43blwWCXxx9oL3qYLQ.jpeg)

**Step 5 — Create zip files to upload**

![](https://cdn-images-1.medium.com/max/697/1*muFnFWm_L6Jmw9xEqOu0zg.jpeg)

After you have done this for all folders, it should look like:

![](https://cdn-images-1.medium.com/max/745/1*VWT3oJ68EZSy6TfQAa1icg.jpeg)

**Step 6 — Drag and drop zip files into assets section**

![](https://cdn-images-1.medium.com/max/871/1*UCHlioP_q-0UNTRjg7CX4w.jpeg)

**Step 7 — Create two classes**

- RaspberryModelAPlus
- RaspberryModelBPlus

**Step 8 — Drag and drop training files into respective folders**

![](https://cdn-images-1.medium.com/max/983/1*pJ3Osm5SJ2GJ2oZZCHSgKw.jpeg)

**Step 9 — That’s all ! Now let’s train this custom model**

![](https://cdn-images-1.medium.com/max/1024/1*adsYZaAKE7rFJz2PI4NE_g.jpeg)

**Step 10 — Time to test our model**

Once the model is trained, the page will give you a link to test the model. The first page on that link summarizes the model.

![](https://cdn-images-1.medium.com/max/1024/1*2Uo1b2Wbujf-KCVvOCovEQ.jpeg)

Click on the Test tab.

I downloaded some test images with different angles and backgrounds to see how the model performs.

![](https://cdn-images-1.medium.com/max/1024/1*zZB8LgkYhb5hLEc0VNa-nQ.jpeg)

Drag and drop the images on the test page.

**Test Results**

**_1. Raspberry Pi Model A Plus in an open enclosure._**

![](https://cdn-images-1.medium.com/max/1024/1*CP7PGgY6Q3LD-HBeUBZXNw.jpeg)

0.89 is not too shabby, given that we did not have any of the training pictures inside an open enclosure.

**_2. Raspberry Pi Model A Plus side angle._**

![](https://cdn-images-1.medium.com/max/1008/1*UhXDJaguL1WJovjxZ6H-8A.jpeg)

We did not have any training pictures with this angle. That explains the low confidence interval.

**_3. Raspberry Pi Model A Plus in a closed board with pins not visible._**

![](https://cdn-images-1.medium.com/max/1021/1*NJXzvY57VsztvwfNkvZztg.jpeg)

This picture is very vague. I would argue that even humans would have a very low confidence. In this case, the model identifies this as the wrong board altogether.

**_4. Raspberry Pi Model B Plus in somebody’s hand._**

![](https://cdn-images-1.medium.com/max/1024/1*JvWQt1ZK7zqz9cRB50a14A.jpeg)

I was hoping to trick the model with this picture by introducing a person and also making the actual board smaller. But the model does relatively well here with a confidence score of 0.65. This can definitely be improved by training on pictures of people holding the pi in their hands.

**_5. Raspberry Pi Model B Plus in a color that was absent in the training images._**

![](https://cdn-images-1.medium.com/max/1011/1*ePi-kZAHufjpi7_gOFBVxA.jpeg)

The confidence interval is low for both models. I imagine this is because all of our training images were green color. The model creates layers or information to teach itself and one of those crucial pieces of information is color. So even though the test image has the right structure, the model had never seen a red color pi before. This can again be rectified by including red color images in the training set.

**_6. Raspberry Pi Model B Plus on top of a box with a long range shot._**

![](https://cdn-images-1.medium.com/max/1024/1*hURHi37oq_VCfRvJ3KF3dQ.jpeg)

The training data has all closeups and this test image is a little far from the camera. The lesson here is that the training set needs to have as much variation as possible.

**_7. Raspberry Pi Model B Plus in an enclosure with no pins visible._**

![](https://cdn-images-1.medium.com/max/1024/1*6detXg8xOC5DN2aIjP_GGg.jpeg)

**_8. BeagleBoard_**

![](https://cdn-images-1.medium.com/max/1024/1*c0o9DdGWqptJ06PDRAzWZA.jpeg)

![](https://cdn-images-1.medium.com/max/1024/1*u0KbJBaE_6syU6sD1QuWjA.jpeg)

The last two images here are from a different board. That particular board (not these pictures themselves) was part of the negative set the model was trained on. Therefore, it correctly identifies this board as neither of the test classes.

#### Summary

So there you have it. We built a custom model on Watson Visual Recognizer and trained it to detect different versions of Raspberry Pi boards without writing any line of code or understanding the ins and outs of machine learning. **Your model is as good as the images it has been trained on.** If I were to take a photo with my iPhone and test against this model, I expect it to give me low confidence on both classes.

Next blog in this series will talk about the various APIs available by the cognitive service to programmatically classify images. We will build a simple application on Glitch, which happens to be my favorite online application ❤️

![](https://cdn-images-1.medium.com/max/1024/1*5yNGzixlXiuuzGrmYmwiMg.jpeg)

[Nick Bourdakos](https://medium.com/u/154a0d2814f0) has another wonderful [article which extends into CoreML on Watson](https://hackernoon.com/simplify-adding-ai-to-your-apps-core-ml-say-hello-to-watson-c4dfebf66802).

* * *