The ideas behind machine learning have been around for decades, and the combination of fast hardware and continued research have provide an explosion of applications. One of the most powerful is Visual Recognition. With IBM Watson Visual Recognition you have access to APIs to classify images, but more importantly, you can create custom classifiers that will give power to your unique use cases. So, how to create a custom classifier, and how to do this using Watson Visual Recognition’s free tier? Let’s have a look…

The free tier of Watson Visual Recognition allows you to classify 250 images per day and train a custom classifier using 5000 images across an unlimited number of classes. One of the best practices for creating a custom classifier is to provide as much data as possible. Even though the API will accept as few as 10 per class, we strongly recommend using a significantly greater amount of images to improve the performance and accuracy of your classifier, such as 100s or 1000s of images. With that in mind, I’ll show how to create a custom classifier with both the CLI and the web UI.

Prerequisites

Steps

Using the CLI

Use your image files that you wish to classify. Each category of image that you wish to classify should be in it’s own zip file, and for each you will need a label of the form:

{class}_positive_examples

For example, you can use the following files to create a classifier for dogs: beagles.zip huskies.zip golden-retriever.zip and for a negative example: cats.zip

Then, simply upload the files to create the classifier using curl. The files that serve as examples should be of the form:

<name>_positive_examples

and negative examples can just have the form:

negative_examples

Here’s how we do it with the example files, substituting the API key you have in your credentials for {api_key} and adding the path to the files you are using if they are not in the current directory:

curl -X POST \
--form "beagle_positive_examples=@beagle.zip" \
--form "husky_positive_examples=@husky.zip" \
--form "goldenretriever_positive_examples=@golden-retriever.zip" \
--form "negative_examples=@cats.zip" \
--form "name=dogs" \
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"

Using the web UI

But what if you are not a command line geek, and you just want a convienient web UI? No problem, just visit:

https://watson-visual-recognition.ng.bluemix.net

and enter your API key.

You’ll be able to upload your classes and negative examples:

Using the files from the CLI example above, the UI form looks like this:

Click Create and that’s it! The training will take some time, depending on how many files are used to train the model.

You can now classify images in the web UI or using the CLI, or any way you can access the REST API in your own application.