Search code examples
pythontensorflowkerasshapesactivation

How to find the shapes of activations in the different layers of a pretrained InceptionResNetV2 model in Keras - Tensorflow 2.0


I have load the inceptionResNetV2 Keras model

base_model = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights='imagenet')

I want to find the shapes of the activations outputed by different layers -- assuming a standard input size of (299x299).

My ultimate goal is to make an informed decision on what part of the pre-trained model to retain untrained (using also other criteria).

I tried:

base_model.summary()

Which returns:

enter image description here

Similarly when I try:

enter image description here

In other words I am getting the depth (number of filters) of the activation tensor but not the Width/Height.

What should I do to find the shape of activations once I input a (299x299) image to the network?


Solution

  • You can put the input_shape in the function by

    base_model = tf.keras.applications.inception_resnet_v2.InceptionResNetV2(include_top=False, weights='imagenet', input_shape=(299, 299, 3))
    

    But this will raise an error if input images aren't 299*299 so better use it only when you want to know the shape.