我正在尝试使用我在Google存储空间中的文件进行预测,但是我不知道我是否使用正确的方法来获得具有正确分数的响应,因为我遇到的问题很严重有关分类的回应。
我正在使用Laravel 5.8和google / cloud-automl V1软件包。
我的代码:
$client = new PredictionServiceClient();
try {
// get full path of model
$formattedName = $client->modelName(
$projectId,
$location,
$modelId
);
// create payload
$textSnippet = (new TextSnippet())
->setContent($content)
->setMimeType('text/plain'); // Types: 'text/plain', 'text/html'
$payload = (new ExamplePayload())
->setTextSnippet($textSnippet);
// predict with above model and payload
$response = $client->predict($formattedName, $payload);
$annotations = $response->getPayload();
// display results
foreach ($annotations as $key => $annotation) {
$classification = $annotation->getClassification();
if ($classification->getScore() > $score) {
$nombre_clase = $annotation->getDisplayName();
$score = $classification->getScore();
}
}
} finally {
printf('Predicted class name: %s' . PHP_EOL, $nombre_clase);
printf('Predicted class score: %s' . PHP_EOL, $score);
$client->close();
}
我的回应(PHP-Laravel):
Predicted class name: cedula Predicted class score: 0.48398617
预期的响应(使用Python中的cURL测试)
Predicted class name: desprendible_fiduprevisora Predicted class score: 0.9996581077575684
您已经看到,PHP上的预测类不是Python,而正确的预测是Python。
对此有任何想法吗? :/