我想知道是否可以给某个表达式的输出命名,以便在代码的另一部分从图中检索它。
例如
def A(a, b): c = a + b d = d * a return d
出于调试目的,如果我能退出 c 在另一个位置,而不通过整个函数层次结构返回。
c
有什么想法吗?
提前感谢!
我假设 a b
a
b
要么你给一个名字 c 使用 tf.identity
tf.identity
def A(a, b): c = a + b c = tf.identity(c, name = "c") d = d * a return d
要么你使用 tf.add 操作而不是 +
tf.add
+
def A(a, b): tf.add(a, b, name = "c") d = d * a return d
不管怎样,你都会得到 c tf.get_variable('c:0') (如果有的话,您可能需要精确确定范围。)
tf.get_variable('c:0')