简体   繁体   English

无法加载预训练的模型

[英]Unable to load a pretrained model

After training my model for almost 2 days 3 files were generated: 在对我的模型进行了将近2天的训练之后,生成了3个文件:

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

where best_model is my model name. 其中, best_model是我的模型名称。 When I try to import my model using the following command 当我尝试使用以下命令导入模型时

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

I get the following error 我收到以下错误

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.

How to fix this? 如何解决这个问题?

I have referred this post: TensorFlow, why there are 3 files after saving the model? 我已经提到了这篇文章: TensorFlow,为什么保存模型后会有3个文件?

  • Tensorflow version 1.0.0 installed using pip 使用pip安装Tensorflow版本1.0.0
  • Linux version 16.04 Linux版本16.04
  • python 2.7 python 2.7

The importer can't find a very specific function in your graph, namely attn_add_fun_f32f32f32 , which is likely to be one of attention functions . 导入程序无法在您的图形中找到非常具体的功能,即attn_add_fun_f32f32f32 ,它很可能是关注功能之一

Probably you've stepped into this issue . 可能您已涉足此问题 However, they say it's bundled in tensorflow 1.0. 但是,他们说它捆绑在tensorflow 1.0中。 Double check that installed tensorflow version contains attention_decoder_fn.py (or, if you are using another library, check that it's there). 所安装tensorflow版本仔细检查包含attention_decoder_fn.py (或者,如果你使用的是其他库,检查它的存在)。

If it's there, here are your options: 如果有,这里是您的选择:

  • Rename this operation , if possible. 如果可能,请重命名此操作 You might want to read this discussion for workarounds. 您可能需要阅读此讨论以了解解决方法。
  • Duplicate your graph definition, so that you won't have to call import_meta_graph , but restore the model into the current graph. 复制您的图定义,这样您就不必调用import_meta_graph ,而是将模型还原到当前图中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM