【问题标题】:Tensorflow 0.8 Import and Export output tensors problemsTensorflow 0.8 导入和导出输出张量问题
【发布时间】:2016-04-26 23:26:27
【问题描述】:

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

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

我想知道是否有人对这个问题有想法。谢谢!!!

【问题讨论】:

  • 为了澄清,您的图形结构在迭代之间是否发生变化,或者您只是想导入一组不同的权重?
  • @mrry 实际上,我只想在不更改图形结构的情况下导出/导入不同的权重集:) 我认为 Tensorflow 0.8 中的导入/导出可能存在错误。 (而且我很确定我的代码没有问题,因为它适用于 Tensorflow 0.6)
  • 这听起来确实像导入器中的一个错误 - 您是否将变量传递给 tf.import_graph_def() 中的 input_map?但是,我认为您的主要问题可以通过简单地使用tf.train.Saver 从不同的检查点保存和恢复来解决。
  • @mrry 好吧,我在我的代码中肯定使用了saver。我认为这里的问题是变量命名问题,应该在0.8中打破。而0.8在内部构建的字典中找不到变量名。
  • 我仍然不清楚您如何使用tf.import_graph_def()。可能是时候将其移至GitHub issue

标签: import export neural-network tensorflow python-3.5


【解决方案1】:

tf.import_graph_def 就是这样工作的。

如果您不需要前缀,只需将name 参数设置为空字符串,如下例所示。

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

【讨论】:

  • 感谢您的回答!基本上,我使用了与您在此处显示的相同的导入功能。我的目标是在训练期间每 50 次迭代自动导出/导入网络状态。正如我在我的问题中提到的,exportimport 第一次运行良好,但第二次导入网络时,它遇到了问题:找不到某些操作...例如,ValueError: Specified colocation to an op that does not exist during import: Variable_10 in Variable/read_1。我使用 tf 0.6 尝试了完全相同的代码,一切运行良好。我猜它在 0.8 内就坏了
  • raise ValueError('tf.import_graph_def() requires a non-empty name ' ValueError: tf.import_graph_def() requires a non-empty name if input_map 被使用。跨度>
猜你喜欢
  • 1970-01-01
  • 2023-01-25
  • 2017-12-16
  • 2023-03-07
  • 2020-03-17
  • 2017-06-25
  • 2016-03-10
  • 2011-05-08
相关资源
最近更新 更多