使用TensorFlow-Adent保存模型时出错
我正在尝试使用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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tl; dr
确保您具有正确的TensorFlow-robability版本,该版本适用于2.9.x和TF-Actents 0.11.0
(
0.19.0
for Tf> 2.11
,0.18.0
for Tf2.10
或查看发行说明)还确保从笔记本中重新启动内核。
问题是
structureCoder已移动到TensorFlow API。因此,其他依赖的库也进行了更改,例如。您的计算机以某种方式拾取了一个旧版本,该版本取决于
nested_structure_coder
的先前版本。对我来说,我正在使用
TensorFlow 2.9.0
TF代理0.13.0
TensorFlow-probabilities 0.17.0
尝试在笔记本中进行明确导入:
Tl;dr
Make sure you have the right tensorflow-probability version that is compatible for 2.9.x and tf-agents 0.11.0
(
0.19.0
for TF2.11
,0.18.0
for TF2.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: