I am currently stuck trying to implement the train_step() function for transfer learning. I am getting an AttributeError: ‘list’ object has no attribute ‘get_shape’.
I would very much appreciate some help.
Thanks!
I am currently stuck trying to implement the train_step() function for transfer learning. I am getting an AttributeError: ‘list’ object has no attribute ‘get_shape’.
I would very much appreciate some help.
Thanks!
This error comes from the compute_layer_style_cost(a_S, a_G)
, UNQ_C3 function. But I am wondering why this happens. This same code, as instructed in the notebook, “To retrieve dimensions from a tensor X, use: X.get_shape().as_list()
”, is working in my case.
Are you changing something or have passed all the above tests?
I have passed all previous tests and I have not changed anything, not that I know of. I only added cells after the error so I could look at shapes and outputs.
Here is a screenshot of my compute_layer_style_cost() function:
{moderator edit - solution code removed}
It looks like your compute_layer_style_cost
logic is correct, so there must be something wrong in the train_step
logic that results in the a_G
value being a list when it should be a tensor. A perfectly correct function can throw errors if you pass it arguments that don’t match its expectations. Please have a look at the train_step
logic to understand what went wrong.
train_step() function is primarily calling other functions. So I’m guessing I should call another function for a_G. I’m posting the entire UNQ_C5 block and the error message. If nothing seems wrong, I will restart the assignment to ensure a more careful approach.
# mentor edit: code removed
Right, so the question is where is a_G generated? Maybe start by printing the type of it right after the call to vgg_model_outputs
. What does that show? Is it wrong on the first iteration or on some subsequent iteration? Then work your way backwards one step at a time. Are you sure you didn’t modify any of the cells that aren’t graded? You can also compare to a clean notebook to make sure (see the FAQ Thread topic on that).
Seeing the exact same error on this exercise:
I tried to verify if I have made a mistake in previous steps, but it didn’t seem so:
fwiw, changing from a_G = vgg_model_outputs(generated_image)
to a_G = tf.Variable(vgg_model_outputs(generated_image))
seems to have updated the error message:
Try doing this instead:
print(f"type(a_G) {type(a_G)}")
But curiously when I do that, I get the type as “list” but it does not cause any kind of problem for me. There must be something different about your notebook. Please check your DMs for a message from me about how to proceed here.
Ok, we just need to look at how the code works. At the top level a_G
is a list, but the elements of the list are tensors. Then compute_style_cost
(which is written for us) extracts the individual layers and passes them individually to compute_style_layer_cost
which is where the error was being thrown for @andreyrmacedo earlier on this thread.
Ok, one way to get the error about a_G
being a list is to call compute_layer_style_cost
directly from train_step
, instead of calling compute_style_cost
. Note that in the style case, there are multiple layers used and the job of compute_style_cost
(which was just provided for you) is to “peel off” the individual style layers and call compute_layer_style_cost
for each one.
Hi. i got the same problem but because I was applying in first instance the wrong function to get the overall style cost. That was for me.
That was me too. I have gotten stuck at least once on every assignment for a similar kind of issue. I’m very thankful for the forum because in every case, there’s been some conversation that has helped me see what was should have been obvious!
I’ve run into the same problem and have determined the issue is around the indexing in the a_G step which in generalized code is:
a_G = vgg_model_outputs(generated_image)[index]
The problem is really determining the right index for ‘block5_conv4’, which somehow makes this step different than the a_C and a_S formulations which do not require indexes. Here’s those blocks of code respectively:
preprocessed_content = tf.Variable(tf.image.convert_image_dtype(content_image, tf.float32))
a_C = vgg_model_outputs(preprocessed_content)
preprocessed_style = tf.Variable(tf.image.convert_image_dtype(style_image, tf.float32))
a_S = vgg_model_outputs(preprocessed_style)
This is massively frustrating to debug. Can you please help?
Have you read the earlier posts on this thread (e.g. this one)? You should not have to do any layer indexing directly in the train_step
function. That means you are probably making the mistake of not calling compute_style_cost
but trying to use compute_style_layer_cost
directly. They specifically provided you a function that handles the indexing issue that you describe.
That was it. What a stupid mistake. Fixed it easy. Ugh. Thank you.