C5 W1 A3 Problem with reshape in djmodel()

Hi,

I’m trying to solve the first exercise of the 3rd assignment of week 1 in the Sequence Models course. I’m having some problems with the code. I won’t put my code as per the code of honor, but I’m getting the following error in the reshape layer:

InvalidArgumentError: Input to reshape is a tensor with 2 values, but the requested shape has 180 [Op:Reshape]

In the previous step, I have sliced X to a shape=(None, 90), and I’m passing the tuple (1, n_values) as an argument to the reshaper layer.

Can anyone guide as to where I’m going wrong?

Happy to share the code by DM if it helps.

Instruction says, Step 2.B: Use reshaper to reshape x to be (1, n_values) (≈1 line). It means you have to pass x which is the shape of (None, 90) as an argument to the reshaper, and then it will return the (1, n_values) shape.

1 Like

Brilliant, thank you! I was implementing all the layer functions wrong

the reshaper for actually returns x as (None,1,n_values), in my case (None,1,90). Is this right or I should have (1,n_values)

When i run the output = summary(model)

I get the following error:


AttributeError                            Traceback (most recent call last)
<ipython-input-53-2ad560a25ebc> in <module>
      2 
      3 # UNIT TEST
----> 4 output = summary(model)
      5 comparator(output, djmodel_out)

~/work/W1A3/test_utils.py in summary(model)
     34     result = []
     35     for layer in model.layers:
---> 36         descriptors = [layer.__class__.__name__, layer.output_shape, layer.count_params()]
     37         if (type(layer) == Conv2D):
     38             descriptors.append(layer.padding)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in output_shape(self)
   2190                            'ill-defined for the layer. '
   2191                            'Use `get_output_shape_at(node_index)` '
-> 2192                            'instead.' % self.name)
   2193 
   2194   @property

AttributeError: The layer “reshape” has multiple inbound nodes, with different output shapes. Hence the notion of “output shape” is ill-defined for the layer. Use get_output_shape_at(node_index) instead.

I have the same output as you have. I added some print statements in my code and below are a few lines from a long loop:

Shape of x after Step 2.A: (None, 90)
Shape of x after Step 2.B: (None, 1, 90)

You can add print statement to check yours:

print(f"Shape of x after Step 2.A: {x.shape}")
# Step 2.B: Use reshaper to reshape x to be (1, n_values) (≈1 line)
x = None
print(f"Shape of x after Step 2.B: {x.shape}")

This error went away for me after rerunning the notebook. That is, I was seeing this error with all the code being correct.

There are lots of ways that the notebook state can get out of sync, e.g. manually running cells out of order. The way to get everything in sync is:

Kernel → Restart and Clear Output
Save
Cell → Run All

Of course the grader does not need to see your output, so you can submit after just the “restart and clear”, plus a “Save” just to make sure.