image_size = 256 #image size which is input shape of the densenet121
base_model=get_base_model('densenet121',image_size) #calling densenet121 using transfer learning
base_in=base_model.input #base_in.shape = (None, 256, 256, 3)
base_out=base_model.output #base_out.shape = (None, 8, 8, 1024)
#function which performs attention which is to be added on the densenet121
def BAM_Channel_Attention(inputs):
shape=K.int_shape(inputs)
x=tf.keras.layers.AveragePooling2D(pool_size=(shape[1],shape[2]))(inputs)
dense = layers.Dense(1280, activation="relu")(x)
reduction = Conv2D(shape[3]/16,1, padding='same')(dense)
dense = layers.Dense(1280, activation="relu")(reduction)
out = tf.keras.layers.BatchNormalization()(dense)
return out
the above function is called here:
#calling the attention function with the output of the densenet121
x=BAM_Channel_Attention(base_out) #
print(x.shape)
I get the output (None, 1, 1, 1280). How can I change the feature map from 1x1x1280 to say 8x8x1280?