Tensorflow 0.8 Import and Export output tensors problems

纵饮孤独 提交于 2020-01-14 07:44:12

问题


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!!!


回答1:


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="")
    [...]


来源:https://stackoverflow.com/questions/36877559/tensorflow-0-8-import-and-export-output-tensors-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!