watson-developer-cloud / node-sdk

:comet: Node.js library to access IBM Watson services.
https://www.npmjs.com/package/ibm-watson
Apache License 2.0
1.48k stars 669 forks source link

[visual-recognition] Custom classifier_ids is not accepted, it keeps defaulting to "default" classifications #558

Closed devanshah2 closed 6 years ago

devanshah2 commented 6 years ago

Description

Issues that was found was with in, https://github.com/watson-developer-cloud/node-sdk where it did not work when custom classifier IDs were provided. The specific issue in the code was at: https://github.com/watson-developer-cloud/node-sdk/blob/master/visual-recognition/v3.js#L271 There was a change in the extend that causes an merge to not work anymore and it would always default to default classifier so it would never use the custom one provided.

Steps to reproduce

Following is an example NodeJS script that can he used to testing things, once an APIKey and custom classifier is created and the ID(s) are provided.

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

var visual_recognition = new VisualRecognitionV3({
    api_key: '<API KEY>',
    version_date: VisualRecognitionV3.VERSION_DATE_2016_05_20
});

var vizParams = {
    images_file: fs.createReadStream(path.join(__dirname, "image1.png")),
    parameters: {
        classifier_ids: ["<custom ID>"]
    }
};

visual_recognition.classify(vizParams, function (err, data) {
    if (err) {
        console.log(err);
    } else {
        if (data && data.images && data.images.length > 0) {
            data.images.forEach(image => {
                var classifiers = image.classifiers;
                classifiers.forEach(classifier => {
                    var classes = classifier.classes;
                    console.log(classes);
                    classes.forEach(classifierClass => {
                        var imageAlt = classifierClass.class + " (" + classifierClass.score + ")";
                        console.log(imageAlt);
                    });
                });
            });
        } else {
            console.log("asdfasdfasdfasdf");
        }
    }
});

Expected Behaviour

Takes the custom classifier_ids provided and applies this classifier instead of default.

Actual Behaviour

When custom classifier_ids are provided it only does the classification with default

Node version: 8.9.1

SDK Version: 2.42.0

ammardodin commented 6 years ago

@devanshah2 Thanks for reporting the issue. The reason why the classify method is using the default classifier is because you're not passing classifier_ids as a top level parameter.

In the current version of the SDK, The classify operation expects classifier_ids as a top level parameter.

Try the following, and it should resolve your issue:

var vizParams = {
    images_file: fs.createReadStream(path.join(__dirname, "image1.png")),
    classifier_ids: ["<custom ID>"]
};

I am closing the issue, but please feel free to reopen if you're still having problems.