Home > Blockchain >  Get mean and reduce channels of feature maps
Get mean and reduce channels of feature maps

Time:03-03

I have a feature map of size 1 x 5 x 5 x 32 and I would like reduce the feature maps channels from 1 x 5 x 5 x 32 to 1 x 5 x 5 x 1 ( from 32 channels reduce to 1 channel ). The only channel is the mean value of the original 32 channels, how can I do that?

Below is my feature map output:

        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)

CodePudding user response:

Try:

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)
  • Related