title: Access to intermediate layers in Keras Functional Model
body: <p>I am using a transfer learning model is a ay very similar to that explained in <a href="https://keras.io/guides/transfer_learning/" rel="nofollow noreferrer">Chollet's keras Transfer learning guide</a>. To avoid problems with the batch normalization layer, as stated in the guide and many other places, I have to insert the original pretrained base model as a functional model with the training=false option like this:</p>
  <pre><code>  inputs = layers.Input(shape=(224,224, 3))
    x = img_augmentation(inputs)
    baseModel = VGG19(weights=&quot;imagenet&quot;, include_top=False,input_tensor=x)
    x=baseModel(x,training=False)
  
    # construct the head of the model that will be placed on top of the
    # the base model
    x=Conv2D(32,2)(x)
    headModel = AveragePooling2D(pool_size=(4, 4))(x)
    headModel = Flatten(name=&quot;flatten&quot;)(headModel)
    headModel = Dense(64, activation=&quot;relu&quot;)(headModel)
    headModel = Dropout(0.5)(headModel)
    headModel = Dense(3, activation=&quot;softmax&quot;)(headModel)
    model = Model(inputs, outputs=headModel) 
  </code></pre>
  <p>My problem is that I need to use gradcam as in <a href="https://keras.io/examples/vision/grad_cam/" rel="nofollow noreferrer">Chollet's gradcam example page</a>.  To do this I need access to the basemodel last convolutional layer but when I summarize my model I get:</p>
  <pre><code>Model: &quot;model_163&quot;
  _________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  input_3 (InputLayer)         [(None, 224, 224, 3)]     0         
  _________________________________________________________________
  img_augmentation (Sequential (None, 224, 224, 3)       0         
  _________________________________________________________________
  vgg19 (Functional)           (None, 7, 7, 512)         20024384  
  _________________________________________________________________
  conv2d_2 (Conv2D)            (None, 6, 6, 32)          65568     
  _________________________________________________________________
  average_pooling2d_2 (Average (None, 1, 1, 32)          0         
  _________________________________________________________________
  flatten (Flatten)            (None, 32)                0         
  _________________________________________________________________
  dense_4 (Dense)              (None, 64)                2112      
  _________________________________________________________________
  dropout_2 (Dropout)          (None, 64)                0         
  _________________________________________________________________
  dense_5 (Dense)              (None, 3)                 195       
  =================================================================
  Total params: 20,092,259
  Trainable params: 67,875
  Non-trainable params: 20,024,384
  __________________________________________
  </code></pre>
  <p>Thus, the outputs I need are inside one of the vgg19 functional model layers. How can I access this layer without having to remove the training=True option?</p>