【问题标题】:using add_done_callback() and reponse.metadata() for automl使用 add_done_callback() 和 reponse.metadata() 进行 automl
【发布时间】:2020-03-23 23:42:00
【问题描述】:

我正在尝试使用 automl 的标准示例。我希望 create_model 能够启动一个长时间运行的操作,一旦完成就会更新操作响应,然后访问元数据(以获取新训练模型的 model_id)。但是脚本在metadata = response.metadata()"TypeError: 'OperationMetadata' object is not callable" 上立即失败。

如果有任何区别,我将在 Airflow/google composer 中的 PythonOperator 中运行此代码。我可以在 AutoML UI 中看到模型开始正确训练。

我的代码是这样的,但是it's basically the example usage that's in the docs.:

from google.cloud import automl

client = automl.AutoMlClient()

...
response = client.create_model(project_location, my_model)

def callback(operation_future):
   # Handle result.
   result = operation_future.result()

response.add_done_callback(callback)
metadata = response.metadata()

我正在使用 google-cloud-automl==0.9.0

【问题讨论】:

标签: google-cloud-composer google-cloud-automl google-cloud-python


【解决方案1】:

我遇到了同样的问题。文档中的那个例子真的让我误入歧途。如果您在响应上调用result() 方法,它实际上会等到模型完成训练后再返回任何内容,这就是您需要做的所有事情。然后,您可以从该结果中获取 model_id。

import time
from google.cloud import automl

client = automl.AutoMlClient()

...
response = client.create_model(project_location, my_model)

model_id = response.result().name.split('/')[-1]

【讨论】:

    【解决方案2】:

    https://googleapis.dev/python/automl/latest/gapic/v1beta1/tables.html 有帮助吗?它是基于 automl.AutoMlClient 构建的手动编写的 Python SDK。

    【讨论】:

      【解决方案3】:

      我建议不要使用您在此处提供的示例 basic usage that's in the docs.:

      最好使用 Google Cloud AutoML Operators How-to Guides Using Operators Google Cloud Operators

      使用 auto_ml 特定运算符是在 Airflow/Composer 环境中实现 Auto_ML 模型的推荐方法。

      这里是 Python Client for Cloud AutoML API 的完整 API 参考

      【讨论】:

        猜你喜欢
        • 2020-10-15
        • 2020-01-22
        • 2020-11-20
        • 2021-02-14
        • 1970-01-01
        • 1970-01-01
        • 2019-01-15
        • 1970-01-01
        • 2017-11-04
        相关资源
        最近更新 更多