Tensorflow 0.8进出口产出张量问题 [英] Tensorflow 0.8 Import and Export output tensors problems

查看:491
本文介绍了Tensorflow 0.8进出口产出张量问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Tensorflow 0.8与Python 3.我正在训练神经网络,目标是每50次迭代自动导出/导入网络状态。问题是当我在第一次迭代时导出输出张量,输出张量名称为 ['Neg:0','Slice:0'] ,但是当我导出输出张量在第二次迭代时,输出张量名称更改为 ['import / Neg:0','import / Slice:0'] ,并导入此输出张量不起作用:

  ValueError:指定在导入期间不存在的op的托管:import /导入/变量/读

我想知道有没有人有这个问题的想法。谢谢!!!

解决方案

这就是 tf.import_graph_def 的作品。 / p>

如果您不想要前缀,只需将名称参数设置为空字符串,如下所示将模型导入到当前图形
中,将tf.Graph()。as_default()作为图形导入到

 
const_graph_def = tf.GraphDef()
with open(TRAINED_MODEL_FILENAME,'rb')as saved_graph:
const_graph_def.ParseFromString(saved_graph.read())
#替换当前图形与保存的图形def(和内容)
#name =是重要的,因为否则(name = None)
#图形定义将以前缀作为前缀。
#eg:定义的操作FC2 / unscaled_logits:0
#将导入/ FC2 / unscaled_logits:0
tf.import_graph_def(const_graph_def,name =)
[。 ..]


I am using Tensorflow 0.8 with Python 3. I am trying to train the Neural Network, and the goal is to automatically export/import network states every 50 iteration. The problem is when I export the output tensor at the first iteration, the output tensor name is ['Neg:0', 'Slice:0'], but when I export the output tensor at the second iteration, the output tensor name is changed as ['import/Neg:0', 'import/Slice:0'], and importing this output tensor is not working then:

ValueError: Specified colocation to an op that does not exist during import: import/Variable in import/Variable/read

I wonder if anyone has ideas on this problem. Thanks!!!

解决方案

That's how tf.import_graph_def works.

If you don't want the prefix, just set the name parameter to the empty string as showed in the following example.

# import the model into the current graph
with tf.Graph().as_default() as graph:

    const_graph_def = tf.GraphDef()
    with open(TRAINED_MODEL_FILENAME, 'rb') as saved_graph:
      const_graph_def.ParseFromString(saved_graph.read())
      # replace current graph with the saved graph def (and content)
      # name="" is important because otherwise (with name=None)
      # the graph definitions will be prefixed with import.
      # eg: the defined operation FC2/unscaled_logits:0
      # will be import/FC2/unscaled_logits:0
      tf.import_graph_def(const_graph_def, name="")
    [...]

这篇关于Tensorflow 0.8进出口产出张量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆