C4 W4 A2: Multiple output layers passed to get_layer_outputs

Hello,

I was curious what kind of model is built with the layers being passed to get_layer_outputs() in section 5.4 Load Pre-trained VGG19 Model

vgg_model_outputs = get_layer_outputs(vgg, STYLE_LAYERS + content_layer)

I printed out model.summary() and also printed out the layer names as previously done in the notebook.

for layer in model.layers:
print(layer.name)

The layers seem to be the same layers as the initial vgg model with the absence of the last block5_pool layer. In fact passing only the block5_conv4 layer into this function produces the same layers in the constructed model. Is this because the block5_conv4 layer is already connected to all of the previous layers as it came from the vgg model? Is there something else happening with this model when constructing it by passing in multiple output layers or would passing only block5_conv4 produce the same results?

Thanks,
David

Hi David,

Welcome to the community.
Here’s a link that you can take help of in finding out what actually happens, when you use a vgg model.

Let me explain with a following figure.

Vgg19 has a fully connected layer marked in blue in the left most figure. As we set “include_top=False” to remove those layers, what you see is the model ended with a MaxPooling2D layer. (middle) Output from this model is (m, 12, 12, 512) where “m” is the number of samples.

Then, we create a model for Neural Style Transfer.
To define our model, as you indicates, we set layers to get outputs by get_layer_outputs().
And, we set STYLE_LAYERS (‘block1_conv1’, ‘block2_conv1’, ‘block3_conv1’, ‘block4_conv1’ and ‘block5_conv1’), and content_layer(‘block5_conv4’).

Then, the model becomes the right one in the first figure. As the last output layer is ‘block5_conv4’, we no longer have a ‘block5_pool’ layer.

If you look at just vgg_model_outputs.summary(), it looks similar to vgg.summary(). We just do not have a ‘block5_pool’ layer. But, output is totally different. Now, the output from our new model is the list of 6 outputs. Each is extracted in a layer that we specified. First 5 outputs are from “style layers” (marked in pink), and the last one is from “content layer” (marked in green).

Here is a quick check.

Hope this helps.

Thank you for the explanations. This makes more sense now when I consider that a model can have multiple outputs rather than just one from the last layer.

Thanks,
David