W4_A2 dimension of a_C and a_G

Why are content_output and generated_output five dimensional in the compute_content_cost function? What is the fifth dimension? Shouldn’t it be four dimensional?

This was all explained in the notebook, but you really had to read and understand all the code that they just gave you. Take a look at the section which defines the function get_layer_outputs. They then use that function to instantiate a model which they assign to the name vgg_model_outputs and it is configured to return a list of 5 entries for the 5 style layers that we have selected, followed by one entry for the content layer.

Here’s a screenshot in which I added some print statements to show a bit more about what is happening there:

So you can see that content_targets and style_targets are lists with 6 entries as described above. Then remember how compute_content_cost and compute_style_cost work: they manage the 6 layers appropriately for their purpose. In compute_content_cost, it selects the last element and only works on that, whereas compute_style_cost trims off the last element and then iterates over the remaining elements.

1 Like

Here’s another thread from a while ago that covers this in a bit more detail.