简体   繁体   English

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

[英]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.

相关问题 无法在Google Automl上进行预测 - Unable to make prediction on google automl Docker 上的 Google Cloud AutoML 预测 - Google Cloud AutoML prediction on Docker 如何在Pandas DataFrame中操纵来自Google AutoML的预测响应? - How to manipulate prediction response from Google AutoML in a Pandas DataFrame? 如何使用 FASTAI 库更改多标签分类预测的阈值 - How to change the threshold of a prediction of multi-label classification using FASTAI library 如何在 Keras 中设置预测阈值? - How to set prediction threshold in Keras? 如何使用python更改图像中的强度阈值 - How to change intensity threshold in an image using python 如何使用谷歌云 AutoML 创建数据集 - How to create a dataset with google cloud AutoML 如何使用 anaconda 为 python 安装 google.cloud automl_v1beta1? - How to install google.cloud automl_v1beta1 for python using anaconda? 如何使用 Python API 从 Google AutoML Vision 导出 tflite 模型? - How to export a tflite model from Google AutoML Vision using Python API? 如何将 automl 模型(使用 autosklearn )转换为 pmml? - How to convert automl model ( using autosklearn ) to pmml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM