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] node sdk throws exception when training a custom classifier #465

Closed TitiHl closed 7 years ago

TitiHl commented 7 years ago

Hi,

I am using watson-developer-cloud: 2.32.1 and trying to train a classifier like following with the attached zip files. it throws the following exception:

[2017-06-01 17:59:52.447] [ERROR] train - { [Error] code: 406 }
Error
    at Request._callback (/Users/alexli/Documents/WebstormProjects/git/prod-authoring-watson/node_modules/watson-developer-cloud/lib/requestwrapper.js:97:15)
    at Request.self.callback (/Users/alexli/Documents/WebstormProjects/git/prod-authoring-watson/node_modules/request/request.js:188:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/Users/alexli/Documents/WebstormProjects/git/prod-authoring-watson/node_modules/request/request.js:1171:10)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)
    at IncomingMessage.<anonymous> (/Users/alexli/Documents/WebstormProjects/git/prod-authoring-watson/node_modules/request/request.js:1091:12)
    at IncomingMessage.g (events.js:260:16)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:921:12)
    at /Users/alexli/Documents/WebstormProjects/git/prod-authoring-watson/node_modules/log4js-client/node_modules/dx-request-context/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
    at nextTickCallbackWith2Args (node.js:442:9)
    at process._tickDomainCallback (node.js:397:17)
    at process.fallback [as _tickCallback] (/Users/alexli/Documents/WebstormProjects/git/prod-authoring-watson/node_modules/log4js-client/node_modules/dx-request-context/node_modules/continuation-local-storage/node_modules/async-listener/index.js:529:15)

However, it works fine when I create the classifier via the tool UI:

http://visual-recognition-tooling.mybluemix.net/ 16c5c410369164acacaaf017da0e10d3.zip 16c5c410369164acacaaf017da0e5443.zip

nfriedly commented 7 years ago

That error comes from the service itself, although a 406 status code and no actual error message seems odd. Can you post your code (minus the API Key) so I can try and replicate it?

TitiHl commented 7 years ago

Yep,

static train(classifier: string, trainFolder: string, positive_classIds: Array<string>) {
    logger.debug(`Start sending data to Watson for training for classifier: ${classifier}`)

    return new Promise(function(resolve, reject) {

        let params = {
            name: classifier
        }

        for (let entry of positive_classIds) {
            let className = entry // where className are the classId that are digits like:
                  16c5c410369164acacaaf017da0e10d3
            logger.debug(`${className} with ${trainFolder}/${entry}.zip`)
            params[`${className}_positive_examples`] =
                fs.createReadStream(`${trainFolder}/${entry}.zip`)
        }

        console.log(1, JSON.stringify(params))

        visual_recognition.createClassifier(params,
            function(err, response) {
                if (err) {
                    logger.error(err)
                    reject(err)
                } else {
                    let result = response
                    logger.debug(result)
                    resolve(result)
                }
            }
        )
    })
}
TitiHl commented 7 years ago

Also, when I lookup the failed case: curl -X GET "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers/[Failed_classifier_id]?api_key=[myAPIKey]&version=2016-05-20"

it always return "explanation": "Cannot execute learning task. : Could not train classifier. Verify there are at least 10 positive training images for each class, and at least 10 other unique training images (inluding optional negative_examples). There is a minimum of 1 positive class." although the attached train data has more than 10 images for each zip.

TitiHl commented 7 years ago

Hiya, do you get any updates on this? it is affecting our product demo. Thanks, Alex

chughts commented 7 years ago

I suspect that this is an URP. I also suspect that there is a problem in your code, in which case this is not the right forum to continue this discussion. Please raise a question on https://developer.ibm.com/answers/topics/watson/ where we will try and debug your code.

In the process of that discussion if we do find that the root cause is the SDK or the Service, then we can come back to this issue on this repository.

nfriedly commented 7 years ago

Hey @TitiHl, I apologize, we're launching a new thing and are kind of underwater with last-minute preparations right now.

@chughts thanks! I'd appreciate it if you can get to the bottom of this.

TitiHl commented 7 years ago

Thanks all,

I have created an issue in https://developer.ibm.com/answers/topics/watson/ please have a look and advise.

Cheers, Alex

brianofrokk3r commented 7 years ago

@TitiHl @germanattanasio is this still occurring?

chughts commented 7 years ago

Forum post is https://developer.ibm.com/answers/questions/379587/visual-recognition-node-sdk-throws-exception-when/

Error response was 406 - implying an accept header problem. Progress was halted due to the problem going away when the account was updated, not sure what effect that would have had. Unless a 406 was being raised when the account allocation was being exhausted as a result of the call, but that doesn't make sense.

TitiHl commented 7 years ago

I think it is ok to close this issue as it turns out a problem of API key.