A Robot Befriends Classic Monsters Using Watson APIs — Part 2

Introduction To Watson Visual Recognition Custom Classifiers Using NodeJS

Nick Bourdakos
IBM watsonx Assistant
3 min readMay 22, 2017

--

Steps 1–3. Credentials, Set Up, and Data Collection

Refer to part one.

Note: If you’re really lazy, like me, just skim through step one and once you have your api key hop back over here and download these training files. Although, I highly recommend reading through if you are interested in learning a bit about some best practices when it comes to creating a good training set.

Step 4. Create Custom Classifiers

Once you go through the first steps of part one you should have all the required training data. This part of the tutorial will be using the NodeJS SDK.

Even though this is the NodeJS section, personally, I would train my classifier using Curl commands from the terminal. Or using this super amazing web app I built.

cd to the location of your zip files, if you’re on a mac and downloaded the files above I’ll save you some typing:

If you wanted to create a classifier named “monsters” with a class for “mummy”, “dracula”, “frankenstein”, and “wolfman”, just run this command from terminal and be sure to replace {api-key} with the api-key you received in step 1:

Note: Make sure you add “_positive_example” to all of your class names.

This may take several minutes because it has to upload all the files, but once it’s done you should get something like this back:

Important: “classifier_id”: “monsters_1680254220” is very important, this is what you will use to classify an image in the next step.

Note: Your classifier_id will be different from mine.

While we wait, I’ll explain why and when you would actually want to use NodeJS. Mainly, because it gives me the chance to teach you lots of things.

The biggest reason would be if you wanted to retrain your classifier, with new images, directly from your app. This, however, requires retraining not training. Showing training wouldn’t actually help too much, but if you’re interested in updating classifiers I’ll give you a link to the documentation. It’s very useful.

Note: For some reason the NodeJS example for update is blank so I’ll give you a hint… And by hint I mean here’s the code:

Step 5. Classify Image

This part should actually be in NodeJS because you will want it to be integrated into your app.

Make sure you install the node module/library:

Then here’s the NodeJS code to classify an image. Make sure you change the classifier_id to the one you received in the previous step. And of course you can replace the Dracula file with whatever file you want to test:

Then run it:

You should get something along the lines of this as your output:

Congratulations! Your computer can now see things, stay tuned for the next steps.

--

--