我正在尝试自动化GCP AI平台中的模型部署。即,在成功训练模型之后,我将模型和源程序包打包并上传到GCS,然后将其部署为新版本并设置为默认版本。我的训练脚本结尾处有这个。我需要这个,因为模型会定期重新训练。
在训练脚本中,打包和上传(用gsutil
调用subprocess
)工作正常,但是在尝试部署新版本时遇到了权限问题。我尝试过
gcloud ai-platform
呼叫subprocess
discovery.build('ml', 'v1').projects().models().versions().create()
呼叫googlecloudapis
我以任何方式收到错误
ResponseError: status=[403], code=[Forbidden], message=[Request had insufficient authentication scopes.]
我已经为AI平台(service-xxxxxxxxx@cloud-ml.google.com.iam.gserviceaccount.com
,Google Cloud ML引擎服务代理)的服务帐户添加了足够的权限,但是没有用。
在训练实例中似乎使用了一个不同的帐户。 discovery.build('ml', 'v1')._http.credentials._service_account
返回default
而不是电子邮件。
在继续使用Cloud Function监视训练脚本的导出之前,我想问一下我是否错过了任何内容,或者是否还有其他选择?
谢谢。
答案 0 :(得分:0)
我查看了服务帐户权限,并看到了Cloud ML Engine Admin,Developer和Viewer。
下面的一些示例代码:
来自here
Usually, you'll create these credentials with one of the helper
constructors. To create credentials using a Google service account
private key JSON file::
credentials = service_account.Credentials.from_service_account_file(
'service-account.json')
Or if you already have the service account file loaded::
service_account_info = json.load(open('service_account.json'))
credentials = service_account.Credentials.from_service_account_info(
service_account_info)
Both helper methods pass on arguments to the constructor, so you can
specify additional scopes and a subject if necessary::
credentials = service_account.Credentials.from_service_account_file(
'service-account.json',
scopes=['email'],
subject='user@example.com')
来自here
def get_client(service_account_json):
"""Returns an authorized API client by discovering the Healthcare API and
creating a service object using the service account credentials JSON."""
api_scopes = ['https://www.googleapis.com/auth/cloud-platform']
credentials = service_account.Credentials.from_service_account_file(
service_account_json)
scoped_credentials = credentials.with_scopes(api_scopes)
return discovery.build(
'ml',
'v1',
credentials=scoped_credentials)