2

I am using Visual Recognition curl command to add a classification to an image:

curl -u "user":"password"  \
-X POST \
-F "images_file=@image0.jpg" \
-F "classifier_ids=classifierlist.json" \
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classifiers?version=2015-12-02"

json file:

{
  "classifiers": [
    { 
        "name": "tomato",
        "classifier_id": "tomato_1",
        "created": "2016-03-23T17:43:11+00:00",
        "owner": "xyz"
    }
  ]
}        

(Also tried without the classifiers array. Got the same error) and getting an error: {"code":400,"error":"Cannot execute learning task : no classifier name given"}

Is something wrong with the json?

Gilad M
  • 942
  • 10
  • 12

2 Answers2

3

To specify the classifiers you want to use you need to send a JSON object similar to:

{"classifier_ids": ["Black"]}

An example using Black as classifier id in CURL:

curl -u "user":"password"  \
-X POST \
-F "images_file=@image0.jpg" \
-F "classifier_ids={\"classifier_ids\":[\"Black\"]}"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"

If you want to list the classifier ids in a JSON file then:

curl -u "user":"password"  \
-X POST \
-F "images_file=@image0.jpg" \
-F "classifier_ids=@classifier_ids.json"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"

Where classifier_ids.json has:

{
 "classifier_ids": ["Black"]
}

You can test the Visual Recognition API in the API Explorer.
Learn more about the service in the documentation.

German Attanasio
  • 22,217
  • 7
  • 47
  • 63
  • Neither one of the suggestion above works. I got the same error: {"code":400,"error":"Cannot execute learning task : no classifier name given"} each time. Also, the schema model for the API document referenced above has a different format: Model Schema { "classifier_id": "string", "name": "string", "owner": "string", "status": "string", "created": "string" } – Gilad M Mar 24 '16 at 04:47
  • I am not clear on the significant of this particular API. If the purpose of this api is to train the visual recognition module with a new classifier, then it doesn't seem that it does it, or at least not to the appearance. I didn't get a new classifier_id after successfully invoking the API as I do when I used the other post API (/v2/classifiers) with positive and negative images. I also don't see the new classifier when using the GET classifiers query, nor do I see the very same classifier when I get the classification for the exact image I just classified. – Gilad M Mar 25 '16 at 10:04
  • The API call above is to classify an image. If you want to create a classifier you need to zip files with positive and negative examples, the result of creating a classifier is a `classifier_id` and that's what you use to classify images. Take a look at the documentation https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/visual-recognition/api/v2/#create_a_classifier – German Attanasio Mar 25 '16 at 14:50
2

The model schema you are referencing, and what is listed in the API reference, is the format of the response json. It is an example of how the API will return your results.

The format of the json that you use to specify classifiers should be a simple json object, as German suggests. In a file, it would be:

{
"classifier_ids": ["tomato_1"]
}

You also need to use < instead of @ for the service to read the contents of the json file correctly. (And you might need to quote the < character on a command line since it has special meaning (redirect input).) So your curl would be:

curl -u "user":"password"  \
-X POST \
-F "images_file=@image0.jpg" \
-F "classifier_ids=<classifier_ids.json"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"