0

我正在使用 Watson Visual Recognition 并成功创建了一个自定义分类器。分类器显示它已准备好并具有以下状态:

{
"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"
}

我正在执行以下 curl 命令来测试这个分类器:

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

而painting.json文件的内容如下:

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

运行此查询将返回以下结果:

{
"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
}

视觉识别显然没有使用我的分类器文件,我可能错过了一些非常明显的东西。关于我错过了什么的任何想法?我在这里关注文档:https ://www.ibm.com/watson/developercloud/visual-recognition/api/v3/#classify_an_image其中指出 JSON 参数是:

classifier_ids - 用于对图像进行分类的分类器 ID 数组。

所有者- 具有值“IBM”和/或“”的数组,用于指定要运行的分类器。

threshold - 一个浮点值,指定必须在响应中显示的类的最低分数。

4

3 回答 3

2

您的 painting.json 文件中的数组classifier_ids应该有 1 个条目:( "paintings_----"使用数字 id 而不是破折号)而不是类名(水、拼贴画等)。

因为它无法将类名理解为classifier_id,所以API从“默认”通用分类器返回结果(因此字段“custom_classes:0”)

此外,owners如果使用该字段应该是复数 - 但是,"owners": "me"它是告诉 API 使用所有自定义分类器并跳过默认分类器的简写。在您的情况下,您确切知道要调用哪个分类器 ID,因此您可以省略该owners字段。我只是仔细检查了文档示例,发现我们需要针对这两个问题修复 API 参考中的示例。

感谢您在问题中包含所有详细信息,并祝您服务好运!

于 2016-11-09T23:08:10.017 回答
0

@Matt ...文档中似乎存在更大的错误。我尝试了 JSON 文件的结构,它被称为 via -F "parameters=@paintings.json"。我想到 json 文件的参数元素可能与 curl 语句中的参数标识符重复。我的 json 文件现在看起来像这样:

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

这适用于 Bluemix Public 和 Bluemix Dedicated。

于 2016-11-10T12:27:04.010 回答
0

尝试将阈值更改为 0.5。为我工作。不知道为什么。

于 2018-03-12T06:01:57.930 回答