Hi friend and mentor,
Q1, in the section of " Excercise 1 - compute_content_cost", what’s the meaning of the 1st 1 in a_C or a_G ? My understanding is 4D only, like shape = [m, n_H, n_W, n_C]
I already passed this section with the correct value, and I saw the code that does a_C = content_output[-1]
but not clear about this 1st “1”
Q2, in the section of Exercise 3 - compute_layer_style_cost. I just got the right value, but not sure if I am just lucky or maybe hardcoded something. The hint says as below. My question is, where is this m go ? m is the number of the sample, is this correct? Since the m is “gone” in the hint, i code as below, i have the [-1] there. is this correct?
# Reshape the images from (n_H * n_W, n_C) to have them of shape (n_C, n_H * n_W) (≈2 lines)
a_S = tf.transpose(tf.reshape(a_S[-1],shape=[n_H * n_W, n_C]))
thanks for your time.
Everything is dealing with only one sample here, but they keep the standard format of the tensors with the samples dimension even if the size is 1. Also note that in the case of the style cost, you have values from multiple layers to worry about also. So you may see either 4 or 5D tensors, but the layers and samples dimension sizes will always be 1 by the time you end up writing the code. That’s also why you need to be careful to use -1 as the index of the last dimension, rather than assuming it’s either 3 or 4, since you need to handle both cases.
1 Like
hi Paul, the answer for my Q1 is that 1st 1 is nothing. I don’t need to care about it ? In the function of “compute_content_cost”, those 2 lines (with [-1]) are already given, not from me. so I assume this 1st 1 is not just for testing but had some meaning. maybe … layers ?
The answer of Q2 is, I do [-1] is correct? am I right?
The m means the number of samples, right?
Those lines are dealing with what I alluded to in my previous reply: look at how they actually construct the tensors that are actually being used in the real training. They “stack” all 5 style layers first and then append the content layer at the end. So that logic is extracting the content entry from the “stack” of layers, right?
Look at the logic in the style cost section: there they discard the last element, rather than taking only the last element.
1 Like