ibm-watson-cognitive Visual Recognition Train a custom classifier


Example

Training a custom classifier requires a corpus of images organized into groups. In this example, I have a bunch of images of apples in one ZIP file, a bunch of images of bananas in another ZIP file, and a third group of images of things that are not fruits for a negative set. Once a custom classifier is created, it will be in state training and you'll have to use the classifier ID to check if it is ready (using the 'Get information about a specific custom classifier' example).

'use strict';

let watson = require('watson-developer-cloud');
let fs = require('fs');

var visualRecognition = watson.visual_recognition({
  version: 'v3',
  api_key: process.env.API_KEY,
  version_date:'2016-05-19'
});


let custom_classifier = {
  apple_positive_examples: fs.createReadStream('./apples.zip'),
  banana_positive_examples: fs.createReadStream('./bananas.zip'),
  negative_examples: fs.createReadStream('./non-fruits.zip'),
  name: 'The Name of My Classifier'
}

visualRecognition.createClassifier(custom_classifier, function(error, results) {
  console.log(JSON.stringify(results,null,2));
});