2017-01-14 33 views
0

在Tensorflow,占位符必须只如果目标依赖于它喂:现在如何调试节点评估的原因?

x = tf.placeholder(tf.int32, [], "x") 
y = 2 * x1 
y = tf.Print(y, ["Computed y"]) 
z = 2 * y 

# Error: should feed "x" 
z.eval() 

# OK, because y is not actually computed 
z.eval({y: 1}) 

,在我更复杂的图形,我有我得到一些占位符不喂一个错误的问题,但我认为他们不应该被需要,通过上述相同的机制。

我该如何调试?该错误消息仅指出需要哪个占位符,但不是为什么。从占位符到目标的路径是有帮助的。

我怎样才能得到这些信息?

回答

2

如果图不是巨大的,你可能只是做反向图搜索的目标节点

def find(start, target): 
    """Returns path to parent from given start node""" 
    if start == target: 
     return [target] 
    for parent in start.op.inputs: 
     found_path = find(parent, target) 
     if found_path: 
      return [start]+found_path 
    return [] 

要使用它

tf.reset_default_graph() 
a1 = tf.ones(()) 
b1 = tf.ones(()) 
a2 = 2*a1 
b2 = 2*b1 
a3 = 2*a2 
b3 = 2*b2 
d4 = b3+a3 
find(d4, a1) 

应该返回

[<tf.Tensor 'add:0' shape=() dtype=float32>, 
<tf.Tensor 'mul_2:0' shape=() dtype=float32>, 
<tf.Tensor 'mul:0' shape=() dtype=float32>, 
<tf.Tensor 'ones:0' shape=() dtype=float32>] 

如果th Ë图是大时,可以通过限制他们

之间

import tensorflow.contrib.graph_editor as ge 
ops_between = ge.get_walks_intersection_ops(source, target) 
ge.get_walks_intersection_ops doc

+0

尼斯,感谢搜索OPS加快步伐!如果TF将这些信息放在错误信息中,那将会很好。或者可能提供一个'AssertNotEvaluated'标识Op,如果违反,则输出该路径。 – Georg