Clarifai cURL 图像识别集成
Clarifai cURL image recognition intergration
我正在尝试使用 cURL 和 PHP 从 Clarifai 图像识别中获取标签。
在他们的网站上有这个用户指南:
https://developer.clarifai.com/guide/#authentication
问题更新
我设法得到了有效的回复,它看起来像这样:
{
"status": {
"code": 10000,
"description": "Ok"
},
"outputs": [
{
"id": "ea68cac87c304b28a8046557062f34a0",
"status": {
"code": 10000,
"description": "Ok"
},
"created_at": "2016-11-22T16:50:25Z",
"model": {
"name": "general-v1.3",
"id": "aaa03c23b3724a16a56b629203edc62c",
"created_at": "2017-08-09T17:11:39Z",
"app_id": null,
"output_info": {
"message": "Show output_info with: GET /models/{model_id}/output_info",
"type": "concept"
},
"model_version": {
"id": "aa9ca48295b37401f8af92ad1af0d91d",
"created_at": "2016-07-13T01:19:12Z",
"status": {
"code": 21100,
"description": "Model trained successfully"
}
}
},
"input": {
"id": "ea68cac87c304b28a8046557062f34a0",
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
}
},
"data": {
"concepts": [
{
"id": "ai_HLmqFqBf",
"name": "train",
"app_id": null,
"value": 0.9989112
},
{
"id": "ai_fvlBqXZR",
"name": "railway",
"app_id": null,
"value": 0.9975532
},
{
"id": "ai_VSVscs9k",
"name": "terminal",
"app_id": null,
"value": 0.9230834
}
]
}
}
]
}
现在,我尝试 foreach 标签:
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("\n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag value is above 93, than show/echo it
}
但是我在 foreach 标签时遇到问题,我无法回显任何标签,我只想显示值高于 93 的标签名称。
尝试:
CURLOPT_CUSTOMREQUEST => "POST"
授权:密钥f26b16808e2a440abb5f28b1c00b6nnn(无括号)
然后
CURLOPT_POSTFIELDS => "{ \"inputs\": [ { \"data\": { \"image\": { \"url\": \"https://samples.clarifai.com/metro-north.jpg\" } } } ] }
它基本上需要匹配位于此处的 cURL 列中的格式:
https://developer.clarifai.com/guide/predict#predict
我正在尝试使用 cURL 和 PHP 从 Clarifai 图像识别中获取标签。
在他们的网站上有这个用户指南: https://developer.clarifai.com/guide/#authentication
问题更新
我设法得到了有效的回复,它看起来像这样:
{
"status": {
"code": 10000,
"description": "Ok"
},
"outputs": [
{
"id": "ea68cac87c304b28a8046557062f34a0",
"status": {
"code": 10000,
"description": "Ok"
},
"created_at": "2016-11-22T16:50:25Z",
"model": {
"name": "general-v1.3",
"id": "aaa03c23b3724a16a56b629203edc62c",
"created_at": "2017-08-09T17:11:39Z",
"app_id": null,
"output_info": {
"message": "Show output_info with: GET /models/{model_id}/output_info",
"type": "concept"
},
"model_version": {
"id": "aa9ca48295b37401f8af92ad1af0d91d",
"created_at": "2016-07-13T01:19:12Z",
"status": {
"code": 21100,
"description": "Model trained successfully"
}
}
},
"input": {
"id": "ea68cac87c304b28a8046557062f34a0",
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
}
},
"data": {
"concepts": [
{
"id": "ai_HLmqFqBf",
"name": "train",
"app_id": null,
"value": 0.9989112
},
{
"id": "ai_fvlBqXZR",
"name": "railway",
"app_id": null,
"value": 0.9975532
},
{
"id": "ai_VSVscs9k",
"name": "terminal",
"app_id": null,
"value": 0.9230834
}
]
}
}
]
}
现在,我尝试 foreach 标签:
$response = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
$header = substr($response, 0, $header_size);
$rows = explode("\n", $header);
$err = curl_error($curl);
curl_close($curl);
$resp = json_decode( $body, true );
if ($err) {echo $err; } else {
// foreach thought tags, and if tag value is above 93, than show/echo it
}
但是我在 foreach 标签时遇到问题,我无法回显任何标签,我只想显示值高于 93 的标签名称。
尝试:
CURLOPT_CUSTOMREQUEST => "POST"
授权:密钥f26b16808e2a440abb5f28b1c00b6nnn(无括号)
然后
CURLOPT_POSTFIELDS => "{ \"inputs\": [ { \"data\": { \"image\": { \"url\": \"https://samples.clarifai.com/metro-north.jpg\" } } } ] }
它基本上需要匹配位于此处的 cURL 列中的格式: https://developer.clarifai.com/guide/predict#predict