2

I was about to create a new classifier and train the visual recognition with pictures, but I got this error code which is stated in title when I curl following command

curl -u "0xxxxxxxxxxx":"vxxxxxxxxxxxxxx" \
 -X POST \
 -F "positive_examples=@bottle-positive.zip" \
 -F "negative_examples=@bottle-negative.zip" \
 -F "name=plasticbottle" \
 -k "https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classifiers?version=2015-12-02"
Yuning
  • 53
  • 4

2 Answers2

1

To set the classifiers you want to use you have to send a JSON containing something like:

{"classifier_ids": ["ClassifierName"]}

So your curl should be something like:

curl -u "username":"pwd"  \
-X POST \
-F "images_file=@imagefilename.jpg" \
-F "classifier_ids={\"classifier_ids\":[\"ClassifierName\"]}"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"
Umberto Manganiello
  • 3,213
  • 9
  • 16
  • i modified your curl command to fit my need, and now it kept running for a while without any feedback – Yuning Apr 04 '16 at 21:36
  • So I ran it on another machine, it says {"code":400,"error":"Could not classify. Verify that the classifier_ids specified are valid and valid images were uploaded."} – Yuning Apr 05 '16 at 02:34
  • Then it looks like to me that I need to use the curl command in my original post to create a classifier, how am I suppose to do that? I tried to reorganize the curl command in a way that send name=plasticbottle before sending zip images, and the error message is Could not train classifier. Verify there are at least 10 positive training images and 10 negative training images that are different from each other."} however I do have 50 different images zip in each. any comment would be greatly appreciated – Yuning Apr 05 '16 at 02:48
  • See here: https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/visual-recognition/api/v2/#create_a_classifier (Section: Create a classifier). That call returns the classifierID that you can use in the above call. – Umberto Manganiello Apr 05 '16 at 05:50
  • Yes, I read that, but isn't that what I had in original post? – Yuning Apr 05 '16 at 14:39
  • Yes it should be the same API. Does it return the classifierId or do you still get the 400 error? – Umberto Manganiello Apr 05 '16 at 14:40
  • I still get 400 error, {"code":400,"error":"Cannot execute learning task : no classifier name given"} – Yuning Apr 05 '16 at 14:54
  • Just tried and it works for me, could you try on the other machine? – Umberto Manganiello Apr 05 '16 at 15:23
  • I tried it on 4 different machines, one vps, one raspberry pi, two school servers, all of them are returning same error, I connect to them via ssh using either a windows 10 or windows 7 machine, used filezila or winscp to upload .zip file to the linux machines, it seems to me that all IBM people who helped me are reporting the curl command works, could it be firewall or something? – Yuning Apr 05 '16 at 15:29
  • Ok, this problem is solved by a friend of mine, people who might have same issue should name their picture neatly, meaning no special symbols, spaces or etc. in the file name of images. – Yuning Apr 05 '16 at 17:39
1

I'm not sure what was the problem using V2 api, but now, using V3 API your CURL should look like this example

curl -X POST
-F "apple_positive_examples=@apples1.zip"
-F "banana_positive_examples=@yellow.zip"
-F "orange_positive_example=@pos_ex.zip"
-F "negative_examples=@vegetables.zip"
-F "name=fruit"
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"

So your CURL for bottle should be like

curl -X POST
 -F "bottle_positive_examples=@bottle-positive.zip"
 -F "negative_examples=@bottle-negative.zip"
 -F "name=plasticbottle"
 "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"

Note that you now should use an api_key to authenticate and no longer a user/pass

This is documented in the v3 doc: https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/#create_a_classifier

Leandro David
  • 577
  • 6
  • 20