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 or train, totalling 1000 events per month. 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 the CLI.

Prerequisites

Steps

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=2019-05-01"