Tensorflow functional API Model build

why is is showing all the layers of VGG19 in the output of features.layers?

layer_outputs = [layer.output for layer in vgg_layers]

layer_outputs = layer_outputs[22:-1]

features = Model(inputs=vgg_input, outputs=layer_outputs)


this is the output of features.layers

[<keras.engine.input_layer.InputLayer object at 0x7fc9224a8750>, <keras.layers.convolutional.Conv2D object at 0x7fc920ad8fd0>, <keras.layers.convolutional.Conv2D object at 0x7fc920b00910>, <keras.layers.pooling.MaxPooling2D object at 0x7fc920222a50>, <keras.layers.convolutional.Conv2D object at 0x7fc9105795d0>, <keras.layers.convolutional.Conv2D object at 0x7fc91057dc10>, <keras.layers.pooling.MaxPooling2D object at 0x7fc910583f50>, <keras.layers.convolutional.Conv2D object at 0x7fc91057d690>, <keras.layers.convolutional.Conv2D object at 0x7fc910588390>, <keras.layers.convolutional.Conv2D object at 0x7fc910592610>, <keras.layers.convolutional.Conv2D object at 0x7fc91058a6d0>, <keras.layers.pooling.MaxPooling2D object at 0x7fc910598e90>, <keras.layers.convolutional.Conv2D object at 0x7fc9105a0410>, <keras.layers.convolutional.Conv2D object at 0x7fc910527ad0>, <keras.layers.convolutional.Conv2D object at 0x7fc910598bd0>, <keras.layers.convolutional.Conv2D object at 0x7fc91052f510>, <keras.layers.pooling.MaxPooling2D object at 0x7fc910578d10>, <keras.layers.convolutional.Conv2D object at 0x7fc9105987d0>, <keras.layers.convolutional.Conv2D object at 0x7fc91053d190>, <keras.layers.convolutional.Conv2D object at 0x7fc910545410>, <keras.layers.convolutional.Conv2D object at 0x7fc91053d7d0>, <keras.layers.pooling.MaxPooling2D object at 0x7fc910554150>, <keras.layers.core.flatten.Flatten object at 0x7fc910557290>, <keras.layers.core.dense.Dense object at 0x7fc91055c490>, <keras.layers.core.dense.Dense object at 0x7fc9105574d0>]

1 answer

  • answered 2022-01-10 05:15 Ravindra Sonawane

    Keras interpret the following line of code as request to create a model with vgg_input as input and layer_outputs as outputs. In this case layer_outputs is a list; therefore, a model with single input and multiple outputs is created. This is why you are getting all the layers as features.layers.

    features = Model(inputs=vgg_input, outputs=layer_outputs)

    If your requirement is to create multiple models with each layer output from layer_outputs as output, you can use following approach with list comprehension:

    features = [Model(inputs=vgg_input, outputs=layer_output) for layer_output in layer_outputs]

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum