gpt4 book ai didi

python - 如何使用 Google AutoML 更改预测阈值?

转载 作者:行者123 更新时间:2023-12-05 03:01:33 26 4
gpt4 key购买 nike

在 google AutoML 中创建模型后,我们可以使用提供的 python 代码进行预测。这是代码:

import sys

from google.cloud import automl_v1beta1
from google.cloud.automl_v1beta1.proto import service_pb2


def get_prediction(content, project_id, model_id):
prediction_client = automl_v1beta1.PredictionServiceClient()

name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id)
payload = {'image': {'image_bytes': content }}
params = {}
request = prediction_client.predict(name, payload, params)
return request # waits till request is returned

if __name__ == '__main__':
file_path = sys.argv[1]
project_id = sys.argv[2]
model_id = sys.argv[3]

with open(file_path, 'rb') as ff:
content = ff.read()

print get_prediction(content, project_id, model_id)

我意识到它只会打印分数高于阈值 value = 0.5 的检测结果。示例输出:

payload {
classification {
score: 0.562688529491
}
display_name: "dog"
}

如何打印分数低于阈值 0.5 的其他检测结果(例如将阈值更改为 0.3)?

最佳答案

请参阅 API 文档 here

params

Object with string properties

Additional domain-specific parameters, any string must be up to 25000 characters long.

For Image Classification:

score_threshold - (float) A value from 0.0 to 1.0. When the model makes predictions for an image, it will only produce results that have at least this confidence score threshold. The default is 0.5.

proto中字段的实际描述是

map<string,string> params;

因此,您可以将已设置为空字典的 params 变量更改。将 params 变量更改为:params = {"score_threshold": "0.3"} 将起作用。

关于python - 如何使用 Google AutoML 更改预测阈值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55645161/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com