У меня есть учетная запись службы, которой я дал роль зрителя, загрузил файл учетных данных json и установил для него правильную переменную среды. Я пытаюсь запустить пример здесь:
def predict_json(project, model, instances, version=None):
"""Send json data to a deployed model for prediction.
Args:
project (str): project where the Cloud ML Engine Model is deployed.
model (str): model name.
instances ([Mapping[str: Any]]): Keys should be the names of Tensors
your deployed model expects as inputs. Values should be datatypes
convertible to Tensors, or (potentially nested) lists of datatypes
convertible to tensors.
version: str, version of the model to target.
Returns:
Mapping[str: any]: dictionary of prediction results defined by the
model.
"""
# Create the ML Engine service object.
# To authenticate set the environment variable
# GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_account_file>
service = googleapiclient.discovery.build('ml', 'v1beta1')
name = 'projects/{}/models/{}'.format(project, model)
if version is not None:
name += '/versions/{}'.format(version)
response = service.projects().predict(
name=name,
body={'instances': instances}
).execute()
if 'error' in response:
raise RuntimeError(response['error'])
return response['predictions']
Однако это дает мне 403 и ошибку The user doesn't have the required permission ml.versions.predict on the resource projects/project/models/model/versions/version
. Я не уверен, что я делаю неправильно - я устанавливаю правильные переменные среды для учетных данных, и, согласно их документации, учетной записи службы требуется только роль зрителя для доступа к этой конечной точке. Что я делаю неправильно?