Course 4 week 4 neural style transfer

I just don’t understand what does those following function do:

content_target = vgg_model_outputs(content_image)

Hi Caroline,

If you look at how the vgg_model_outputs is created by calling this function:
def get_layer_outputs(vgg, layer_names):
“”" Creates a vgg model that returns a list of intermediate output values."""

What you have in that variable is the VGG model. The input for the model is an image and the output is a list of the model outputs for the middle layers.

Let me know if that helped you to understand it better.
Happy deep learning


Thank you for your reply, I am still confused.
sometimes we get the output from a NN through the function model.predict(), why we can use the model() directly here?

Hi Caroline,

Totally fair question. The answer is in the official documentation from tf.keras

predict: Computation is done in batches. This method is designed for performance in large scale inputs. For small amount of inputs that fit in one batch, directly using __call__ is recommended for faster execution, e.g., model(x) , or model(x, training=False)

So basically since we do not have in this case a large amount of data, we can directly call model() instead.
Hope it helps.


Hi Rosa,

Thank you for the answer. Now I totally understand. Thank you so much.



Hi Rosa,

I have inserted a “model.summary()” statement in the get_layer_outputs function and this outputs the structure of the whole VGG network. Should it not only output the desired Block(1,2,3,4,5)Conv1 layers?

Thanks for your help

Hi Antonio,

Without having your full code, I suggest that you add some debugging in your code (maybe with prints before building the model), just to check which list of layers are you passing to the keras Model. Once you check the list of layers is correct, you can build the model.

Good luck and happy learning,


Hi Rosa,

Thanks for your reply.

In the meantime I have read in another post that outputing all the layers is apparently normal and correct. The output layers are just the subset required.

I passed the assignment. Can this be correct?

Happy to read this. I guess if you passed then all is fine :smiley: