Skip to content

Instantly share code, notes, and snippets.

@ivder
Created April 11, 2019 07:50
Show Gist options
  • Save ivder/8c897684dd4502a82a0cefde68686d5c to your computer and use it in GitHub Desktop.
Save ivder/8c897684dd4502a82a0cefde68686d5c to your computer and use it in GitHub Desktop.
Multi images prediction using AutoML generated Model
import sys
import os
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 = "C:/DeepEye/Data/Result/boundingbox_resources/20190409"
project_id = "sunlit-cove-237107"
model_id = "ICN8375020944768203011"
result = open('result.txt', 'w')
for filename in os.listdir(file_path):
filename = file_path +'/' +filename
print filename
with open(filename, 'rb') as ff:
content = ff.read()
#print get_prediction(content, project_id, model_id)
result.write(filename+'\n'+ str(get_prediction(content, project_id, model_id))+'\n')
result.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment