[英]How to change prediction threshold using Google AutoML?
在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文檔
PARAMS
具有字符串屬性的對象
其他特定於域的參數,任何字符串的長度都不得超過25000個字符。
對於圖像分類:
score_threshold-(浮動)從0.0到1.0的值。 當模型對圖像進行預測時,它將僅產生至少具有該置信度分數閾值的結果。 默認值為0.5。
原型中該字段的實際描述是
map<string,string> params;
因此,您將更改已設置為空dict的params變量。 將params
變量更改為: params = {"score_threshold": "0.3"}
將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.