过了几天,GCP AutoML WebUI就无法导出模型以进行离线推理(支援队说,它是一个前端组件错误,已经修复了几天,现在还没有)。
说过,我通常不是图形用户界面的粉丝,我希望我能用CLI或Python google-cloud-automl来完成这项工作。我不得不承认,谷歌在文档方面糟透了,而且他们不停地改变功能,而没有给出细节和例子。虽然各种功能都在工作(桶列表、桶创建、数据上传到桶,甚至模型训练等),但是模型导出一直是一个令人头疼和难以配置的问题。在我们继续之前,请注意GOOGLE_APPLICATION_CREDENTIALS是添加到环境中的。到目前为止,我已经尝试过:
1.通过POST:
# get the token
access_token = subprocess.check_output(
'gcloud auth application-default print-access-token', shell=True)
data = {
"outputConfig": {
"modelFormat": "tf_saved_model", #or "tf-saved-model"
"gcsDestination": {
"outputUriPrefix": "gs://bucket/folder"
}
}
}
headers = {
'Authorization': f'Bearer {access_token.decode().rstrip()}',
'Content-Type': 'application/json; charset=utf-8',
}
url= f"https://automl.googleapis.com/v1/projects/{project_id}/locations/us-central1/models/{model_id}:export"
response = requests.post(url, headers=headers, json=data)Response.content失败:
b'{\n "error": {\n "code": 400,\n "message": "List of found errors:\\t1.Field: name; Message: Required field is invalid\\t",\n "status": "INVALID_ARGUMENT",\n "details": [\n {\n "@type": "type.googleapis.com/google.rpc.BadRequest",\n "fieldViolations": [\n {\n "field": "name",\n "description": "Required field is invalid"\n }\n ]\n }\n ]\n }\n}\n'2.通过google automl
location = "us-central1"
client = automl.AutoMlClient()
model_full_id = client.model_path(project=project_id, location=location, model=model_id)
response = client.export_model(????)显然需要参数(如果我运行它,client.export_model()):
1.字段: name;消息:位置ID未提供。
2.字段:名称;消息:必需字段无效
3.字段: output_config.gcs_destination.output_uri_prefix;消息:为GCS路径或前缀提供空字符串。
我一开始就被困在如何传递论点上。我试图通过location_to_be_written (?)为model_format和automl.types.ModelExportOutputConfig配置元数据,但这本身就是一个麻烦。
发布于 2021-03-25 16:44:23
post方法,需要使用模型id (例如ICN124...、TBL543...)
您可以在UI => AutoML Models选项卡或通过列出你的模型找到您的。
通过遵循您提供的示例,我成功地导出了模型。from google.cloud import automl
project_id = "YOUR_PROJECT"
model_name="projects/YOUR_PROJECT_NUMBER/locations/us-central1/models/YOUR_MODEL_ID"
gcs_uri = "gs://bucket/folder"
client = automl.AutoMlClient()
gcs_destination = automl.GcsDestination(output_uri_prefix=gcs_uri)
output_config=automl.ModelExportOutputConfig(gcs_destination=gcs_destination, model_format="tflite")
request = automl.ExportModelRequest(name=model_name, output_config=output_config)
response = client.export_model(request=request)BTW,从UI导出的问题现在已经解决了,您应该能够从它导出您的模型。
发布于 2021-02-02 03:19:58
我也提出了同样的问题。我以前经常使用WebPage导出模型,到上周初,我甚至能够导出该模型。但是从周五开始就无法导出任何一个离线模型:(不管怎样,我尝试了第一个Post方法,我用代码导出了模型。
https://stackoverflow.com/questions/66002306
复制相似问题