Chaper4 Week4 Assignment 2 Exercise 6

Hi there,
I encounter the following issue

AttributeError: in user code:

    File "<ipython-input-28-02fe63a6c6d3>", line 20, in train_step  *
        J_style = compute_layer_style_cost(a_S, a_G)
    File "<ipython-input-10-8b5b8a52639e>", line 16, in compute_layer_style_cost  *
        _, n_H, n_W, n_C = a_G.get_shape().as_list()

    AttributeError: 'list' object has no attribute 'get_shape'

Here is the code:

       # Compute a_G as the vgg_model_outputs for the current generated image
        #(1 line)
        a_G = vgg_model_outputs(generated_image)
        
        # Compute the style cost
        #(1 line)
        J_style = compute_layer_style_cost(a_S, a_G)

‘vgg_model_outputs(generated_image)’ returns a list of tensors, but ‘compute_layer_style_cost’ function expects ‘a_G’ to be a tensor of dimension (1, n_H, n_W, n_C).

Please let me know if you see how to resolve it. The help is highly appreciated!

There is an error in your compute_layer_style_cost() function.

Do not use () after “get_shape”.

My code uses
... = a_G.shape.as_list()

Still get the same error:

AttributeError: in user code:

    File "<ipython-input-27-02fe63a6c6d3>", line 20, in train_step  *
        J_style = compute_layer_style_cost(a_S, a_G)
    File "<ipython-input-10-c155c320cd90>", line 16, in compute_layer_style_cost  *
        _, n_H, n_W, n_C = a_G.shape.as_list()

    AttributeError: 'list' object has no attribute 'shape'

The problem is “compute_layer_style_cost” function expects “a_G” to be a tensor of dimension (1, n_H, n_W, n_C), but the returned a_G = vgg_model_outputs(generated_image) is a list of tensors:

a_G = [<tf.Tensor 'model/block1_conv1/Relu:0' shape=(1, 400, 400, 64) dtype=float32>, <tf.Tensor 'model/block2_conv1/Relu:0' shape=(1, 200, 200, 128) dtype=float32>, <tf.Tensor 'model/block3_conv1/Relu:0' shape=(1, 100, 100, 256) dtype=float32>, <tf.Tensor 'model/block4_conv1/Relu:0' shape=(1, 50, 50, 512) dtype=float32>, <tf.Tensor 'model/block5_conv1/Relu:0' shape=(1, 25, 25, 512) dtype=float32>, <tf.Tensor 'model/block5_conv4/Relu:0' shape=(1, 25, 25, 512) dtype=float32>]

Still looking for a way to resolve it.

1 Like

The problem is that you should not be calling compute_style_layer_cost directly from train_step. That is the bug. Notice that there is the function compute_style_cost that handles looping over the various layers and calling compute_style_layer_cost for each layer.

2 Likes