您好首先这是我第一次使用谷歌的服务。我正在尝试使用 Google AutoML Vision Api(自定义模型)开发应用程序。我已经构建了一个自定义模型并生成了 API 密钥(我希望我做得正确)。
经过多次尝试通过 Ionics 和 Android 进行开发并且未能连接到 API。
我现在已经在 Python(在 Google Colab 上)中使用了给定代码的预测建模,即使这样我仍然收到一条错误消息,指出无法自动确定凭据。我不确定我在哪里出错了。请帮忙。快死了。
#installing & importing libraries
!pip3 install google-cloud-automl
import sys
from google.cloud import automl_v1beta1
from google.cloud.automl_v1beta1.proto import service_pb2
#import key.json file generated by GOOGLE_APPLICATION_CREDENTIALS
from google.colab import files
credentials = files.upload()
#explicit function given by Google accounts
[https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-python][1]
def explicit():
from google.cloud import storage
# Explicitly use service account credentials by specifying the private key
# file.
storage_client = storage.Client.from_service_account_json(credentials)
# Make an authenticated API request
buckets = list(storage_client.list_buckets())
print(buckets)
#import image for prediction
from google.colab import files
YOUR_LOCAL_IMAGE_FILE = files.upload()
#prediction code from modelling
def get_prediction(content, project_id, model_id):
prediction_client = automl_v1beta1.PredictionServiceClient()
name = 'projects/{}/locations/uscentral1/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
#print function substitute with values
content = YOUR_LOCAL_IMAGE_FILE
project_id = "REDACTED_PROJECT_ID"
model_id = "REDACTED_MODEL_ID"
print (get_prediction(content, project_id, model_id))
运行最后一行代码时的错误消息:
江户川乱折腾
相关分类