Search code examples
tensorflowmachine-learningkerascomputer-visiontransfer-learning

What is the difference between model.get_layer() and model.get_layer().output


I know this is silly question but I am little bit confused here... for I am using transfer learning using VGG16 and it has a layer named 'block4_pool'. so what is the difference between the objects these two lines returns,

base_model.get_layer('block4_pool')
base_model.get_layer('block4_pool').output

what are they returning?


Solution

  • The first one returns a layer object which is a MaxPooling2D layer.

    The second one is the output tensor of this layer.

    let's see what is exactly these are:

    First statement:

    print(base_model.get_layer('block4_pool'))
    
    >>  <tensorflow.python.keras.layers.pooling.MaxPooling2D object at 0x7f50fe7f8ed0>
    

    Second statement:

    print(base_model.get_layer('block4_pool').output) 
    
    >>  KerasTensor(type_spec=TensorSpec(shape=(None, 9, 9, 512), dtype=tf.float32, name=None), name='block4_pool/MaxPool:0', description="created by layer 'block4_pool'")