微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GCP AI Platform统一Python export_model FailedPrecondition:400 不支持以 `` 格式导出工件​​

如何解决GCP AI Platform统一Python export_model FailedPrecondition:400 不支持以 `` 格式导出工件​​

我正在使用 Google AiPlatform(统一)Python 客户端将经过训练的模型导出到 Google Cloud 存储桶。我正在关注以下示例代码export_model_sample.

该应用程序目前具有“所有者”凭据,因为我想确保它不是权限问题。但是,当我尝试执行示例代码时,出现以下错误

回溯(最近一次调用最后一次): 文件“/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py”,第 57 行,在 error_remapped_callable 中 返回 callable_(*args,**kwargs) 文件“/usr/local/lib/python3.8/site-packages/grpc/_channel.py”,第 923 行,调用 返回_end_unary_response_blocking(状态,呼叫,假,无) 文件“/usr/local/lib/python3.8/site-packages/grpc/_channel.py”,第 826 行,在 _end_unary_response_blocking 引发 _InactiveRpcError(state) grpc._channel._InactiveRpcError: <_inactiverpcerror of rpc status="StatusCode.FAILED_PRECONDITION" details='不支持以 <code>projects/101010101010/locations/us-central1/models/123123123123123</code> 格式导出模型 <code>is not supported." debug_error_string = "{"created":"@1611864688.554145696","description":"Error received from peer ipv4:172.217.12.202:443","file":"src/core/lib/surface/call.cc","file_line":1067,"grpc_message":"Exporting artifact for model `projects/110101010101/locations/us-central1/models/123123123123123` in format</code> 的工件。'>

上述异常是以下异常的直接原因:

回溯(最近一次调用最后一次):文件“/app/main.py”,第 667 行,在 response = aiplatform_model_client.export_model(name=name,output_config=output_config) 文件 "/usr/local/lib/python3.8/site-packages/google/cloud/aiplatform_v1beta1/services/model_service/client.py",第 937 行,在 export_model 中 response = rpc(request,retry=retry,timeout=timeout,Metadata=Metadata,) 文件 "/usr/local/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py",第 145 行,调用 返回wrapped_func(*args,**kwargs) 文件“/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py”, 第 59 行,在 error_remapped_callable 中 6.raise_from(exceptions.from_grpc_error(exc),exc) 文件“”,第 3 行,在 raise_from google.api_core.exceptions.FailedPrecondition:400 导出工件 对于模型 projects/111101010101/locations/us-central1/models/123123123123123123 不支持 `` 格式。

(我省略了项目 ID 和模型 ID。使用 10101 和 123123)

我已经验证了我的输入,但似乎一切正常:

gcs_destination_output_uri_prefix = "gs://my-bucket-vcm/model-123123123123123/tflite/2021-01-28T16:00:00.000Z/"
gcs_destination = {"output_uri_prefix": gcs_destination_output_uri_prefix}
output_config = {"artifact_destination": gcs_destination,}
name = "projects/10101010101/locations/us-central1/models/123123123123123"
response = aiplatform_model_client.export_model(name=name,output_config=output_config)
print("Long running operation:",response.operation.name)
export_model_response = response.result(timeout=300)
print("export_model_response:",export_model_response)

我也在使用最新版本的google-cloud-aiplatform==0.4.0 我尝试导出的模型类型为:MOBILE_TF_LOW_LATENCY_1

我只想将模型导出到云存储桶。不要将其部署为服务。

解决方法

export_model_sample 缺少请求字段。您应该在 "export_format_id": string 中包含 output_config。您可以在 AI Platform Unified REST API 参考中进一步探索 export endpoint 所需的必填 output_config 字段。

export_format_id 的可接受值如下:

  • tflite 用于 Android 移动设备。
  • edgetpu-tflite 用于 Edge TPU 设备。
  • tf-saved-model SavedModel 格式的 tensorflow 模型。
  • tf-js 一个 TensorFlow.js 模型,可以在浏览器和 使用 JavaScript 的 Node.js。
  • core-ml 用于 iOS 移动设备。
  • custom-trained 由自定义代码上传或训练的模型。

代码应该是这样的。在本例中,我将 tflite 用于 export_format_id

from google.cloud import aiplatform

def export_model_sample(
    project: str = "your-project-id",model_id: str = "your-model-id",gcs_destination_output_uri_prefix: str = "your-bucket-destination",location: str = "us-central1",api_endpoint: str = "us-central1-aiplatform.googleapis.com",timeout: int = 300,):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once,and can be reused for multiple requests.
    client = aiplatform.gapic.ModelServiceClient(client_options=client_options)
    output_config = {
        "export_format_id": "tflite","artifact_destination": {"output_uri_prefix": gcs_destination_output_uri_prefix}
    }
    name = client.model_path(project=project,location=location,model=model_id)
    response = client.export_model(name=name,output_config=output_config)
    print("Long running operation:",response.operation.name)
    export_model_response = response.result(timeout=timeout)
    print("export_model_response:",export_model_response)

export_model_sample()

我在操作完成后得到一个以这种方式命名的模型:

gs://your-bucket-destination/your-model-id/tflite/2021-01-29T04:15:51.672336Z/model.tflite

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。