将 BigQuery 中生成的 AutoML 模型部署到 AI Platform 时出现问题

问题描述

我无法将使用 BigQuery 创建的 AutoML 模型部署到 AI Platform 以进行在线预测。

我通过 sql 使用标准程序在 BigQuery 中创建了一个 AutoML 模型:

CREATE OR REPLACE MODEL `model_name`
OPTIONS
  (model_type='automl_regressor',budget_hours=2.0,... ) AS
SELECT ...)

这很好用,我能够成功获得预测结果。我现在想部署它进行在线预测。为此,我通过 BigQuery Cloud Console 中的 Export Model 函数将模型导出到 GCS 存储桶。这为我提供了存储桶中的目录,其中包含以下内容

assets/
saved_model.pb
variables/

然后我转到 AI Platform 控制台并创建了一个模型,然后使用以下预构建的容器设置继续为该模型创建一个版本:

  • Python 版本:3.7
  • 框架:TensorFlow
  • 框架版本:2.3.1
  • 机器学习运行时版本:2.3

我已将 Cloud Storage 路径设置为包含我上面列出的内容的目录的存储桶,并继续为我的模型创建版本。这样做后,我在一段时间后收到此错误

Create Version Failed. Bad model detected with error: "Failed to load model: Loading servable: {name: default version: 1} Failed: Not found: Op type not registered 'DecodeProtoSparseV2' in binary running on localhost. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib,accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph,as contrib ops are lazily registered when the module is first accessed.\n\n (Error code: 0)"

有点难住了,因为我认为这是我可以利用从 BigQuery 生成的 ML 模型的方式。这里的步骤有什么问题吗?目前是否有可能部署这样的模型进行在线预测?如果没有,有没有办法转换模型以便部署?任何帮助将不胜感激!

解决方法

据我所知,您已经在 BigQuery ML 中训练了一个 automl_regressor 模型,您打算将其用于 AI Platform 的在线预测。但是,根据 documentation,无法使用 automl_regressor 进行在线预测。

  • 模型类型 AUTOML_REGRESSOR 和 AUTOML_CLASSIFIER 的导出模型 不支持部署 AI Platform 以进行在线预测。

根据您的需要,您可以从 BigQuery ML 列表 here 中选择另一个模型,该模型可以部署用于在线预测。

此外,您还可以直接使用 AutoML 训练您的模型,并将其部署和用于在线预测。不过,请注意 AutoML 模型用于特定的预测要求,例如所描述的 here。此外,您需要按照 documentation 来训练模型。

,

您还可以使用 AutoML 容器/Docker 部署在 BigQuery 中使用文档 here 训练的 AutoML 模型。这类似于导出和部署直接使用 AutoML Tables 训练的模型的方式。