Tensorflow: tf.add()
1.基本用法: 单个数字和单个数字的简单相加。
复制代码
1
2
3
4
5
6
7
8import tensorflow as tf x = tf.constant(2) y = tf.constant(1) z = tf.add(x,y) with tf.Session() as sess: print(sess.run(z))
输出:3
2.广播机制: 即按维度的相加
论文《BiSeNet V2: Bilateral Network with Guided Aggregation for Real-time Semantic Segmentation》中的 Context Embedding Block模块,将1x1xC的特征图和HxWxC的特征图进行相加,即采用广播机制的相加。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12import tensorflow as tf a = tf.constant([[[2,3]]]) b = tf.constant([[[2,3], [1,0,]],[[5,6],[3,2]],[[4,5],[1,8]]]) c = tf.add(a,b) print(a) #Tensor("Const_2:0", shape=(1, 1, 2), dtype=int32) print(b) #Tensor("Const_3:0", shape=(3, 2, 2), dtype=int32) print(c) #Tensor("Add_3:0", shape=(3, 2, 2), dtype=int32) with tf.Session() as sess: print(sess.run(c))
即1x1x2 + 3x2x2 = 3x2x2的输出。
最后
以上就是暴躁糖豆最近收集整理的关于Tensorflow: tf.add()的全部内容,更多相关Tensorflow:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复