germanattanasio / visual-recognition-nodejs

DEPRECATED: this repo is no longer actively maintained
Apache License 2.0
362 stars 351 forks source link

Following documented example results in an error #294

Closed GallagherAiden closed 5 years ago

GallagherAiden commented 5 years ago

I am following the example from here: https://cloud.ibm.com/apidocs/visual-recognition?code=node#create-a-classifier

With the following code:

var VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');
var fs = require('fs');

var visualRecognition = new VisualRecognitionV3({
  version: '2018-03-19',
  iam_apikey: '****'
});

var params = {
  name: 'things',
  visible_positive_examples: fs.createReadStream('./classifier_images/visible_things.zip'),
  faded_positive_examples: fs.createReadStream('./classifier_images/faded_things.zip'),
  covered_positive_examples: fs.createReadStream('./classifier_images/covered_things.zip'),
  wonky_positive_examples: fs.createReadStream('./classifier_images/wonky_things.zip'),
  negative_examples: fs.createReadStream('./classifier_images/negative_things.zip')
};

visualRecognition.createClassifier(params,
  function (err, response) {
    if (err) {
      console.log(err);
    } else {
      console.log(JSON.stringify(response, null, 2))
    }
  });

Which gives the following error:

Error: Missing required parameters: positive_examples
    at Object.getMissingParams (/Users/aideng/Documents/GitHub/video-analyzer/node_modules/ibm-cloud-sdk-core/lib/helper.js:94:11)
    at VisualRecognitionV3.createClassifier (/Users/aideng/Documents/GitHub/video-analyzer/node_modules/watson-developer-cloud/visual-recognition/v3-generated.js:272:50)
    at Object.<anonymous> (/Users/aideng/Documents/GitHub/video-analyzer/classifier_setup.js:18:19)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)

This fails on v4.0.1 but works on version 3.18.2 (albeit with warning)

germanattanasio commented 5 years ago

@SirSpidey ☝️

SirSpidey commented 5 years ago

The example is now changed and reflects the latest version of the SDK

const fs = require('fs');
const VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');

const visualRecognition = new VisualRecognitionV3({
  version: '2018-03-19',
  iam_apikey: '{apikey}',
});

const createClassifierParams = {
  name: 'dogs',
  negative_examples: fs.createReadStream('./cats.zip'),
  positive_examples: {
    beagle: fs.createReadStream('./beagle.zip'),
    husky: fs.createReadStream('./husky.zip'),
    goldenretriever: fs.createReadStream('./golden-retriever.zip'),
  }
};

visualRecognition.createClassifier(createClassifierParams)
  .then(classifier => {
    console.log(JSON.stringify(classifier, null, 2));
  })
  .catch(err => {
    console.log('error:', err);
  });