我试图在GCP AI平台上自动化模型部署。也就是说,在对模型进行成功的培训之后,我将模型和源包打包并上传到GCS,并将其作为新版本部署,并设置为默认版本。我在训练脚本的末尾有这个。我需要这个,因为模型定期重新训练。
在培训脚本中,打包和上传(用subprocess调用subprocess)运行良好,但我在尝试部署新版本时遇到了权限问题。我试过
gcloud ai-platform调用subprocessdiscovery.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引擎服务代理)的服务帐户添加了足够的权限,但是它没有工作。
在培训实例中,似乎使用了不同的帐户。discovery.build('ml', 'v1')._http.credentials._service_account返回default而不是电子邮件。
在继续使用云函数监视来自培训脚本的导出之前,我想问一下是否遗漏了什么或者是否还有其他选项?
谢谢。
发布于 2019-10-10 04:33:04
我查看服务帐户权限,并看到Cloud引擎管理、开发人员和查看器。
下面是一些示例代码:

来自这里
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')来自这里
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)https://stackoverflow.com/questions/58300844
复制相似问题