python - 无法加载预训练模型

标签 python machine-learning tensorflow neural-network chatbot

训练我的模型近 2 天后,生成了 3 个文件:

best_model.ckpt.data-00000-of-00001
best_model.ckpt.index
best_model.ckpt.meta

其中 best_model 是我的模型名称。 当我尝试使用以下命令导入模型时

with tf.Session() as sess:
  saver = tf.train.import_meta_graph('best_model.ckpt.meta')
  saver.restore(sess, "best_model.ckpt")

我收到以下错误

Traceback (most recent call last):

File "<stdin>", line 2, in <module>
File "/home/shreyash/.local/lib/python2.7/site-

packages/tensorflow/python/training/saver.py", line 1577, in 
import_meta_graph
    **kwargs)
  File "/home/shreyash/.local/lib/python2.7/site-

packages/tensorflow/python/framework/meta_graph.py", line 498, in import_scoped_meta_graph
    producer_op_list=producer_op_list)

File "/home/shreyash/.local/lib/python2.7/site-packages/tensorflow/python/framework/importer.py", line 259, in import_graph_def
    raise ValueError('No op named %s in defined operations.' % node.op)

ValueError: No op named attn_add_fun_f32f32f32 in defined operations.

如何解决这个问题?

我引用了这篇文章:TensorFlow, why there are 3 files after saving the model?

  • 使用 pip 安装的 Tensorflow 版本 1.0.0
  • Linux 版本 16.04
  • Python 2.7

最佳答案

导入器在您的图表中找不到非常具体的函数,即 attn_add_fun_f32f32f32,它可能是 one of attention functions .

您可能已经进入 this issue 。然而,他们说它捆绑在 TensorFlow 1.0 中。仔细检查已安装的tensorflow版本是否包含attention_decoder_fn.py(或者,如果您使用的是其他库,请检查它是否存在)。

如果有,您可以选择以下选项:

  • Rename this operation , 如果可能的话。您可能想阅读this discussion寻求解决方法。
  • 复制您的图表定义,以便您不必调用 import_meta_graph,而是将模型恢复到当前图表中。

关于python - 无法加载预训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46566006/

相关文章:

machine-learning - 序数分类包和算法

machine-learning - 逻辑回归中的负对数似然维度

python - DCGAN : discriminator getting too strong too quickly to allow generator to learn

python - 如何在 Arch Linux 中安装 Python 3.8 和 Python 3.9?

python - 在 TF 估计器中使用 Keras 模型

python - 我将如何计算一个单词中辅音的数量? Python

python - 在树莓派上用Python读取NFC标签

python - 将数据集划分为训练和测试后将标签转换为指标矩阵

python - 无法在anaconda上安装tensorflow

python - 将闭合曲线拟合到一组点