W1_A3 Problem with reshape layer

In the definiton of djmodel

  • I initialize the output list as empty list
  • take x as slice of X, I tried both with the notaton I’d use in numpy and with some lambda slicing, both considering X as 3 and 2-dimensional (x = X[:,t,:] and x = X[t,:]), since maybe the “batch” axis doesn’t need to be considered
  • then finally try to reshape x simply by x = reshaper(x)

The model is compiled without errors with
model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)

but then when the following line is called
output = summary(model)

I get the error:

AttributeError Traceback (most recent call last)
----> 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)
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 spent literally hours on the problem, but couldn’t find the solution. I beg for help.

1 Like

I don’t understand this. In instructions, we have:

2A. Select the ‘t’ time-step vector from X.

  • X has the shape (m, Tx, n_values).

  • The shape of the ‘t’ selection should be (n_values,).

  • Recall that if you were implementing in numpy instead of Keras, you would extract a slice from a 3D numpy array like this:

var1 = array1[:,1,:]

Note that every time you modify anything inside djmodel() you must go back and re-run the cell that creates the LSTM_cell() object.


Thank you for your answer. I meant that I had tried every sensible combination I could think of (included x = X[:,t,:]), but the error remained, and it was indeed due to the fact that TMosh mentioned.

That was indeed exactly the problem, thank you.