API платформы GCP AI, доступ запрещен
Я пытался заставить модель Tensorflow работать на платформе AI в GCP. Но когда я позвонил с помощью внешнего API, он вернул:
googleapiclient.errors.HttpError: <HttpError 403 when requesting ***** returned "Access to model denied.">
Я использую учетные данные администратора платформы AI, и ранее он работал на
sklearn
модели, в которых я использовал тот же код, он работал отлично. Есть идеи, что может вызвать проблему?
from google.api_core.client_options import ClientOptions
import googleapiclient.discovery
from google.oauth2.service_account import Credentials
def predict_json(project, region, 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.
region (str): regional endpoint to use; set to None for ml.googleapis.com
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>
credentials = Credentials.from_service_account_file(r"./credentials2.json")
prefix = "{}-ml".format(region) if region else "ml"
api_endpoint = "https://{}.googleapis.com".format(prefix)
client_options = ClientOptions(api_endpoint=api_endpoint)
service = googleapiclient.discovery.build(
'ml', 'v1', client_options=client_options, credentials=credentials)
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']