提供授权 header 以使用 google ml-engine 的方法

Ways to provide authorisation header to use google ml-engine

我目前参与了一个使用 GCP 的项目 Ml-engine。它已经设置好并准备就绪,所以我的任务是使用它的预测命令来利用 API。整个项目存在于 VM 实例中,所以我想知道,它是否有助于以更简洁的方式获取访问令牌?我的意思是,SDK 或类似的东西,因为我没有发现任何有用的东西。如果没有,我在这里有什么选择?智威汤逊?

您可能会发现这很有用。 https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/ml_engine/online_prediction/predict.py

尤其是这些行:

# 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', 'v1')
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()

您可以从项目 IAM 页面创建服务帐户文件并将令牌下载到 VM。