C5W1A3 - Jazz Improvisation - **UPDATE** Issue solved | ERROR at "model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)"

UPDATE Issue solved = Had to restart kernel.

I followed the hints correctly and filled in the appropriate code in the djmodel() function. But I seem to get the below error when running the next code cell not matter what I do.
Kindly help me understand this error!

djmodel Code:
{moderator edit: code removed}


ValueError Traceback (most recent call last)
----> 1 model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)

in djmodel(Tx, LSTM_cell, densor, reshaper)
46 a, _, c = LSTM_cell(inputs=x, initial_state=[a, c])
47 # Step 2.D: Apply densor to the hidden state output of LSTM_Cell
β€”> 48 out = densor(a)
49 # Step 2.E: add the output to β€œoutputs”
50 outputs.append(out)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
925 return self._functional_construction_call(inputs, args, kwargs,
β†’ 926 input_list)
928 # Maintains info about the Layer.call stack.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1090 # TODO(reedwm): We should assert input compatibility after the inputs
1091 # are casted, not before.
β†’ 1092 input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
1093 graph = backend.get_graph()
1094 # Use self._name_scope() to avoid auto-incrementing the name.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
214 ’ incompatible with the layer: expected axis ’ + str(axis) +
215 ’ of input shape to have value ’ + str(value) +
β†’ 216 ’ but received input with shape ’ + str(shape))
217 # Check shape.
218 if spec.shape is not None:

ValueError: Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 90 but received input with shape [None, 64]


I think the problem is in your call to LSTM_cell().
Try removing the β€œinputs=” label from the 'β€˜x’ variable.

@TMosh thanks for the reply. It worked fine after I restarted the Kernel, no changes made.


Thanks for your report.

1 Like

Had the same issue and a kernel restart worked for me as well


Similar issue, but with a different error. My code looked exactly like the one above and worked correctly after a kernel restart

Please see this thread.

The problem is LSTM_cell is defined as a global variable, and is easily broken during debugging. So, you need to reset LSTM_cell like this if there is an error.

LSTM_cell = LSTM(n_a, return_state = True)

Of course, this resets trained weights as well. So, once you fix an error, it is better to re-run all cells.
But, do not need to restart kernel everytime for debugging.

Hi Rajeshm99,

Posting the codes at this platform is a violation. If the query is resolved completely, kindly remove it.


1 Like

Hi Rashmi, I’m unable to delete the code as I’m not able to edit the post.

Oh, yes. Even I’m not able to do so. I think it would be done by the moderator.