【发布时间】:2021-12-27 12:05:57
【问题描述】:
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
上面的函数在这里被调用:
#calling the attention function with the output of the densenet121
x=BAM_Channel_Attention(base_out) #
print(x.shape)
我得到了输出(None, 1, 1, 1280)。如何将特征图从 1x1x1280 更改为 8x8x1280?
【问题讨论】:
标签: python tensorflow keras deep-learning conv-neural-network