获取特征图的均值和减少通道
Get mean and reduce channels of feature maps
我有一个大小为 1 x 5 x 5 x 32 的特征图,我想将特征图通道从 1 x 5 x 5 x 32 减少到 1 x 5 x 5 x 1(从 32 个通道减少到1 个通道)。唯一的通道是原来32个通道的平均值,怎么办?
下面是我的特征图输出:
convOutputs: tf.Tensor(
[[[[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]
[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]
...
[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]
[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]]]], shape=(1, 5, 5, 32), dtype=float32)
尝试:
import tensorflow as tf
x = tf.random.normal((1, 5, 5, 32))
x = tf.reduce_mean(x, axis=-1, keepdims=True)
print(x.shape)
# (1, 5, 5, 1)
我有一个大小为 1 x 5 x 5 x 32 的特征图,我想将特征图通道从 1 x 5 x 5 x 32 减少到 1 x 5 x 5 x 1(从 32 个通道减少到1 个通道)。唯一的通道是原来32个通道的平均值,怎么办?
下面是我的特征图输出:
convOutputs: tf.Tensor(
[[[[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]
[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]
...
[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]
[ 0.21890974 0.2801039 -0.02241993 -0.02482897 -0.02028599
-0.00421949 -0.03049909 0.12293314 -0.00455996 0.16527294
0.25661796 0.08303508 -0.00884647 0.18990402 0.17974378
-0.00271507 -0.01113621 -0.02265824 -0.01211608 -0.02467087
-0.01819963 -0.01684237 0.26299486 -0.01183819 -0.01383558
-0.01530357 -0.02485864 -0.00031154 0.21875194 -0.0014731
-0.02675386 -0.00685479]]]], shape=(1, 5, 5, 32), dtype=float32)
尝试:
import tensorflow as tf
x = tf.random.normal((1, 5, 5, 32))
x = tf.reduce_mean(x, axis=-1, keepdims=True)
print(x.shape)
# (1, 5, 5, 1)