tf.group()和tf.identity()含义

1-tf.group()

最近看tf项目源代码的时候,出现了下面的代码:

train_op = tf.group(main_loss, aux_losss, bottleneck.updates[1])

想把代码改成多GPU训练,因此需要详细了解代码含义。
实际上,通过查询API接口,这行代码相当于把main_loss, aux_losss, bottleneck.updates[1]三个op(算子)合并为了一个op,然后在session run的时候同时执行

2-tf.identity()

讲到tf.group(),顺带提提tf.identity(),因为在tensorflow静态图中,只有节点和节点之前的边(数据流动)。我们如果想做python语法里面常规的操作,比如变量赋值,在tensorflow静态图里面等价于

y=tf.identity(x)

参考链接:

tf.group()用于组合多个操作

TensorFlow笔记——(2) tf.group(), tf.tuple 和 tf.identity()

posted @ 2022-11-13 22:35  dlhl  阅读(212)  评论(0)    收藏  举报