Search code examples
curlclassificationvisual-recognition

Watson Visual-Recognition not using custom classifier


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.


Solution

  • @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.