Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including watson-visual-recognition-utils with all npm packages installed. Try it out:

var watsonVisualRecognitionUtils = require("watson-visual-recognition-utils")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

watson-visual-recognition-utils v0.1.1

Command Line Interface and NPM module for easily creating/updating Watson Visual Recognition customer classifiers.

Visual Recognition CLI Build Status

Command Line Interface for quickly and easily interacting with the Watson Visual Recognition service & custom classifiers.

Getting Started

Make sure you read the documentation for Visual Recognition before using this library.

You must have a valid Visual Recognition key to use this tool. If you do not have one, you can get a free trial here.

npm install watson-visual-recognition-utils -g


Run either the command watson-visual-recognition-utils or wvru in the terminal (both are aliases to the same code), you should see something like this:

$ watson-visual-recognition-utils
Watson Visual Recognition - Custom Classifier Utilities

  Usage:  <command> [options]


    api-usage [options]             View IBM Watson Visual Recognition API Key usage and limits
    classifier-list [options]       List all custom classifiers
    classifier-detail [options]     Fetch custom classifier verbose details
    classifier-classify [options]   Classify an image
    classifier-create [options]     Create a new custom classifier
    classifier-delete [options]     Delete a custom classifier
    key-set <key>                   Save your Watson Visual Recognition key in CLI preferences
    key-unset                       Remove your Watson Visual Recognition key in CLI preference


    -h, --help     output usage information
    -V, --version  output the version number

You can either pass the Visual Recognition key as a CLI parameter, or save it in encrypted preferences so it does not need to be passed with every invocation.

Specify the API key as CLI parameter

This will call the list command, using the API key as a CLI argument:

watson-visual-recognition-utils classifier-list --key YOUR_WATSON_KEY_HERE


First, set the key in preferences

watson-visual-recognition-utils key-set YOUR_WATSON_KEY_HERE

Next, call the list command (key is saved for all subsequent actions)

watson-visual-recognition-utils classifier-list

Create a new classifier

Invoke the classifier-create command. You can specify multiple positive classes, and optionally a negative collection of images, per service specs at:

watson-visual-recognition-utils classifier-create
  • You can specify multiple positive classes
    • requires pairs of --positive-class (string for class name) and --positive-path (path to zip file for positive images).
    • pairs are processed in order specified
  • You can optionally specify a negative zip file
    • contains negative images for the classifier

One positive and one negative:

watson-visual-recognition-utils classifier-create --name classifier_name --positive-class rust --positive-path ./ --negative-path ./

Multiple positive classes and a negative:

watson-visual-recognition-utils classifier-create --name train_parts --positive-class wheels --positive-path ./ --positive-class rails --positive-path ./ --positive-class springs --positive-path ./ --negative-path ./

Classify (invoke a classifier)

Invoke the classify command:

watson-visual-recognition-utils classifier-classify

With CLI arguments:

  • default classifier is system "default"
  • can specify multiple classifiers as comma delimited list (no spaces)
watson-visual-recognition-utils classifier-classify --image ./path/to/image.jpg --classifier_ids default,rust,cracks  

Output from the classify service will be displayed as a JSON object.


This sample code is licensed under Apache 2.0.



Open Source @ IBM

Find more open source projects on the IBM Github Page

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free