Home > Blockchain >  Adding GlobalAveragePooling2D to ResNet50
Adding GlobalAveragePooling2D to ResNet50

Time:02-23

I would like to add "GlobalAveragePooling2D" and Predication (Dense) to my base ResNet50. As show below

enter image description here

So I did this:

x=base_model.output
x = tf.keras.layers.GlobalAveragePooling2D()(x) 
x = tf.keras.layers.Dense(2, activation='softmax')(x)
model =  keras.models.Model(inputs=base_model.input,  outputs=x)
model.summary()

But I got this:

enter image description here

Are they different or the same, because I think I got different results.

CodePudding user response:

They are the same only difference is that you did not give any name to your layers. The summary will be same if you do it like:

x = base_model.output
x = tf.keras.layers.GlobalAveragePooling2D(name = 'avg_pool')(x) 
x = tf.keras.layers.Dense(2, activation='softmax', name = 'predictions')(x)
model =  tf.keras.models.Model(inputs=base_model.input,  outputs=x)
model.summary()
  • Related