2

I have written below code in Node.js to create a classifier and then classify an image using Visual Recognition API Version 3, but the image isn't classified with the created classifier.

Same code has worked with earlier version. Please share your thoughts.

Thanks in advance!

var visual_recognition, params;
var ONE_HOUR = 3600000;
var CLASSIFIERID = [];


    // Create the service wrapper
  visual_recognition = watson.visual_recognition({
     version: 'v3',
     api_key: process.env.API_KEY || '<api-key>',
     version_date: '2015-05-19'
    });

Creating classfier:

params = {
    name: constants.DRIVERNAME, 
    driverOne_positive_examples: fs.createReadStream('./public/positive.zip'),
    negative_examples: fs.createReadStream('./public/negative.zip')
    };

    visual_recognition.createClassifier(params, function(err, classifier) { 
     if (err){          

        res.render('showError',{title:constants.TITLE1,
                                    err:'Something went wrong!'
                                    });
     }

     else{

        CLASSIFIERID.push(classifier.classifier_id);
         }  

    });

Classify image:

var parm = {
      images_file: img_classify,
      classifier_ids: CLASSIFIERID,
      threshold: 0.0
    };

visual_recognition.classify(parm, function(err, results) {
    var driverName,driverScore,driverId,driver;

    if (err){
      console.log('Error at classification!!!');

    }

    else{

        console.log('Image has been classified!!!');
    res.json(results); 
}
joe
  • 2,468
  • 2
  • 12
  • 19
phanindra
  • 21
  • 1
  • What is your error? Do you get any kind of logs? – joe Jul 20 '16 at 19:12
  • Hi Joe, It is not getting Error, but after Classifying the image the "results" JSON is having below data. {"custom_classes":0,"images":[{"classifiers":[],"image":"test.jpg"}],"images_processed":1}. – phanindra Jul 21 '16 at 08:01

1 Answers1

0

You need to specify classifier_ids using an array.

var parm = {
      images_file: img_classify,
      classifier_ids: [CLASSIFIERID], // <--- See this
      threshold: 0.0
    };

visual_recognition.classify(parm, function(err, results) {
    var driverName,driverScore,driverId,driver;

    if (err){
      console.log('Error at classification!!!');

    }

    else{

        console.log('Image has been classified!!!');
    res.json(results); 
}

Visual Recognition Node SDK documentation.

German Attanasio
  • 22,217
  • 7
  • 47
  • 63