0
votes

I am working with Watson Visual Recognition and have successfully created a custom classifier. The classifier shows that it is ready with the following status:

{
"classifier_id": "paintings_----",
"name": "paintings",
"owner": "--- owner id -----",
"status": "ready",
"created": "2016-11-09T14:55:45.835Z",
"classes": [
    {"class": "water"},
    {"class": "collage"},
    {"class": "forest"},
    {"class": "beach"},
    {"class": "still"},
    {"class": "abstract"},
    {"class": "building"},
    {"class": "garden"}
],
"retrained": "2016-11-09T15:11:50.740Z"
}

I am executing the following curl command to test this classifier:

curl -X POST -F "images_file=@IMG_5309.JPG" -F "[email protected]" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={valid API key}&version=2016-05-20&threshold=0.0"

and the paintings.json file has the following content:

{
"parameters":{
  "classifier_ids": [
     "water",
     "collage",
     "forest",
     "beach",
     "still",
     "abstract",
     "building",
     "garden"
    ] ,
  "owner":"me",
  "threshold":".5"
 }
}

Running this query returns the following result:

{
"custom_classes": 0,
"images": [
    {
        "classifiers": [
            {
                "classes": [
                    {
                        "class": "vegetation",
                        "score": 1.0
                    },
                    {
                        "class": "flower",
                        "score": 0.668188,
                        "type_hierarchy": "/products/gifts/flower"
                    },
                    {
                        "class": "purple",
                        "score": 0.268941,
                        "type_hierarchy": "/colors/purple"
                    }
                ],
                "classifier_id": "default",
                "name": "default"
            }
        ],
        "image": "IMG_5309.JPG"
    }
],
"images_processed": 1
}

Visual-Recognition is obviously not using my classifier file and I've probably missed something REALLY obvious. Any ideas on what I've missed? I am following the documentation here: https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/#classify_an_image which states that the JSON parameters are:

classifier_ids - An array of classifier IDs to classify the images against.

owners - An array with the value(s) "IBM" and/or "me" to specify which classifiers to run.

threshold - A floating point value that specifies the minimum score a class must have to be displayed in the response.

3

3 Answers

2
votes

The array classifier_ids in your paintings.json file should have 1 entry: "paintings_----" (with the numeric id instead of the dashes) instead of the class names (water, collage, etc).

Because it is unable to understand the class names as a classifier_id, the API is returning results from the "default" general purpose classifier (hence the field "custom_classes: 0")

Also, the owners field should be plural if used - however, "owners": "me" is a shorthand to tell the API to use all your custom classifiers and skip the default one. In your case you know exactly which classifier_id you want to invoke so you can omit the owners field. I just double-checked the docs example and see we need to fix the example in the API reference on both these issues.

Thank you for including all the details in your question, and good luck with the service!

0
votes

@Matt ... It seems that there is a larger error in the documentation. I experimented with the structure of the JSON file, which is called via -F "[email protected]". It occurred to me that the parameter element the json file might be duplicating the parameter identifier in the curl statement. My json file now looks like this:

{
  "classifier_ids": ["paintings_2--------2"],
  "owners": "me",
  "threshold":"0.0"
}

This works on both Bluemix Public and Bluemix Dedicated.

0
votes

Try changing your threshold to 0.5. Worked for me. No idea why.