使用TensorFlow-Adent保存模型时出错

发布于 2025-02-05 04:13:07 字数 490 浏览 5 评论 0 原文

我正在尝试使用TensorFlow-Agent保存模型。首先,我定义以下内容:

collect_policy = tf_agent.collect_policy
saver = PolicySaver(collect_policy, batch_size=None)

然后保存这样的模型:

saver.save('my_directory/')

这在Google Colab中可以正常工作,但是我在本地PC中遇到以下错误。

AttributeError: module 'tensorflow.python.saved_model.nested_structure_coder' has no attribute 'StructureCoder'

这些是我使用的库版本:

TensorFlow 2.9.1

TF-ADECTENT 0.11.0

I am trying to save a model with tensorflow-agents. First I define the following:

collect_policy = tf_agent.collect_policy
saver = PolicySaver(collect_policy, batch_size=None)

and then save the model like this:

saver.save('my_directory/')

This works ok in google colab but I am getting the following error in my local PC.

AttributeError: module 'tensorflow.python.saved_model.nested_structure_coder' has no attribute 'StructureCoder'

These are the library versions I am using:

tensorflow 2.9.1

tf-agents 0.11.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2025-02-12 04:13:08

tl; dr

确保您具有正确的TensorFlow-robability版本,该版本适用于2.9.x和TF-Actents 0.11.0

pip uninstall tensorflow-probability
pip install tensorflow-probability==0.17.0

0.19.0 for Tf > 2.11 0.18.0 for Tf 2.10 或查看发行说明

还确保从笔记本中重新启动内核。

问题是

structureCoder已移动到TensorFlow API。因此,其他依赖的库也进行了更改,例如。您的计算机以某种方式拾取了一个旧版本,该版本取决于 nested_structure_coder 的先前版本。

对我来说,我正在使用
TensorFlow 2.9.0
TF代理0.13.0
TensorFlow-probabilities 0.17.0

尝试在笔记本中进行明确导入:

import tensorflow_probability
print(tensorflow_probability.__version__) # was 0.17.0 for me

Tl;dr

Make sure you have the right tensorflow-probability version that is compatible for 2.9.x and tf-agents 0.11.0

pip uninstall tensorflow-probability
pip install tensorflow-probability==0.17.0

(0.19.0 for TF 2.11, 0.18.0 for TF 2.10 or look at the release notes)

Also make sure to restart your kernel from the notebook.

What the problem was

StructureCoder has been moved to tensorflow API. Therefore, other dependent libraries have made changes like this in tf-agent and like this in tensorflow-probability. Your machine is somehow picking up an older version that depends on the previous version of nested_structure_coder.

For me, I was using
tensorflow 2.9.0
tf-agents 0.13.0
tensorflow-probabilities 0.17.0

Try making an explicit import in your notebook:

import tensorflow_probability
print(tensorflow_probability.__version__) # was 0.17.0 for me
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文