[英]How to change prediction threshold using Google AutoML?
After creating Model in google AutoML we can use the provided python code to make a prediction. 在google AutoML中创建模型后,我们可以使用提供的python代码进行预测。 Here's the code : 这是代码:
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)
I realize that it will only print detection result that has score above threshold value = 0.5
. 我意识到,它只会打印分数高于阈value = 0.5
检测结果。 Example output : 示例输出:
payload {
classification {
score: 0.562688529491
}
display_name: "dog"
}
How to print the other detection results that has score below threshold 0.5 (eg change threshold to 0.3) ? 如何打印得分低于阈值0.5(例如,将阈值更改为0.3)的其他检测结果?
See the api documentation here 请参阅此处的api文档
params PARAMS
Object with string properties 具有字符串属性的对象
Additional domain-specific parameters, any string must be up to 25000 characters long. 其他特定于域的参数,任何字符串的长度都不得超过25000个字符。
For Image Classification: 对于图像分类:
score_threshold - (float) A value from 0.0 to 1.0. score_threshold-(浮动)从0.0到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. 默认值为0.5。
The actual description of the field in the proto is 原型中该字段的实际描述是
map<string,string> params;
So you would change your params variable that you have set to an empty dict. 因此,您将更改已设置为空dict的params变量。 Change the params
variable to : params = {"score_threshold": "0.3"}
will work. 将params
变量更改为: params = {"score_threshold": "0.3"}
将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.