KeyError: 'SimpleMLLoadModelFromPathWithHandle' while loading model

问题描述 投票:0回答:1

我一直在尝试为我的烧瓶应用加载我保存的随机森林模型, 我提到了这篇

tensorflow.org
文章但是当我加载时我得到这个错误:

FileNotFoundError:

Op 类型未在 b5d47309d41b 上运行的二进制文件中注册“SimpleMLLoadModelFromPathWithHandle”。确保 Op 和 Kernel 已在此过程中运行的二进制文件中注册。请注意,如果您正在加载使用来自 tf.contrib 的操作的已保存图形,则应在导入图形之前访问(例如)tf.contrib.resampler,因为在首次访问模块时会延迟注册 contrib 操作。您可能正尝试在与计算设备不同的设备上加载。考虑将 experimental_io_device 选项 intf.saved_model.LoadOptions 设置为 io_device,例如 '/job:localhost'。

我用下面的代码来保存:

model.save("/content/DSS_project/my_saved_model")

要在上传保存的模型后加载另一个 colab,请使用以下代码

loaded_model = keras.models.load_model('/content/DSS_project/my_saved_model')
loaded_model.compile(metrics=['accuracy'])

我运行了上面文章中提到的以下代码:

!saved_model_cli show --dir "/content/DSS_project/my_saved_model" --all

并得到与上述相同的错误

要在此处复制错误是我的 colab 代码:

colab 文件

通过运行所有单元格,您可以看到全部错误消息

谢谢!

python tensorflow random-forest
1个回答
0
投票

我发现导入

tensorflow_decision_forests
修复了
KeyError: 'SimpleMLLoadModelFromPathWithHandle'
错误。

这是一个对我有用的例子。

import tensorflow as tf
import tensorflow_decision_forests

model = tf.keras.models.load_model('./saved_models/random_forest_model_1')
model.summary()

更多信息可以在这个线程中找到:
https://discuss.tensorflow.org/t/tensorflow-decision-forests-with-tfx-model-serving-and-evaluation/2137/3

[This] 在端二进制文件中加载 TF-DF SavedModel 时可能会遇到错误(例如 TFX 评估器 [取决于 TFX 的版本] 或 C++ TF 服务基础设施)。在这种情况下,您将不得不进行 op 注入:

  • 在 C++ 二进制文件中,可以通过向 //tensorflow_decision_forests/tensorflow/ops/inference:kernel_and_op 12 添加依赖项来注入 OP。
  • 在 Python 二进制文件中,可以在加载模型之前通过导入 TF-DF(即导入 tensorflow_decision_forests)来注入 op。
© www.soinside.com 2019 - 2024. All rights reserved.