在 Tensorflow 中命名表达式的输出 [英] Name the output of an expression in Tensorflow
本文介绍了在 Tensorflow 中命名表达式的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以为某个表达式的输出命名,以便在代码的另一部分从图中检索它.
I wonder whether it's possible to give a name to the output of a certain expression to retrieve it from the graph at another part of the code.
例如
def A(a, b):
c = a + b
d = d * a
return d
出于调试目的,如果我可以在另一个位置拉出 c
而无需在整个函数层次结构中返回它,那就太好了.
For debug purposes it would be nice if I could pull out c
at another position without returning it through the entire function hierarchy.
有什么想法吗?
提前致谢!
推荐答案
我假设 a
和 b
是张量.
I'm assuming a
and b
are tensors.
或者你使用 tf.identity
def A(a, b):
c = a + b
c = tf.identity(c, name = "c")
d = d * a
return d
要么使用 tf.add
操作代替 +
操作:
Either you use the tf.add
operation instead of +
:
def A(a, b):
tf.add(a, b, name = "c")
d = d * a
return d
无论哪种方式,您都可以使用 tf.get_variable('c:0')
检索 c
(如果有,您可能需要精确范围.)
Either way, you get retrieve c
with tf.get_variable('c:0')
(You might need to precise the scope if any.)
这篇关于在 Tensorflow 中命名表达式的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文