画像のアップロードからすべての予測を表示しようとしています。現在、1 つの予測のみが表示されます。score_threshholdを 0に設定すると、すべての予測ではなく、最も可能性の低い予測のみが表示されます。
import io
from google.cloud import automl_v1beta1
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="automl_json.json"
#Provides the image, project id from google cloud, model id from AUTOML
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 = { "score_threshold": "0.2" }
#The response has the image classification and the confidence score for that image
response = prediction_client.predict(name, payload, params)
labels = response.payload # Get labels from response
#Get the classification of that image from labels
image_class=labels[0].display_name
#score_result has has the confidence score for that category
score_result=labels[0].classification
confidence=score_result.score
#print(labels)
return image_class,confidence # waits till request is returned
def fetch_prediction(content,project_id,model_id):
file_path = content
project_id = project_id
model_id = model_id
with open(file_path, 'rb') as ff:
content = ff.read()
classification,confidence=get_prediction(content, project_id, model_id)
#results={classification:confidence}
#results=get_prediction(content, project_id, model_id)
return classification,confidence
別の投稿では、しきい値を低く設定することを提案していましたが、出力が増えません。ありがとう