C5W1A3 music_inference_model: error on dimensions

After running the code “inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)”, there is an error on LSTM_cell().
ValueError: Input 0 is incompatible with layer lstm: expected shape=(None, None, 90), found shape=[90, 1, 1]

Detailed error msgs are shown below. Is it a dimension issue on x?

ValueError Traceback (most recent call last)
----> 1 inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)

in music_inference_model(LSTM_cell, densor, Ty)
40 #print(x.shape)
41 # Step 2.A: Perform oTyne step of LSTM_cell. Use “x”, not “x0” (≈1 line)
—> 42 a, _, c = LSTM_cell(x, initial_state=[a, c])
44 # Step 2.B: Apply Dense layer to the hidden state output of the LSTM_cell (≈1 line)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/recurrent.py in call(self, inputs, initial_state, constants, **kwargs)
707 # Perform the call with temporarily replaced input_spec
708 self.input_spec = full_input_spec
→ 709 output = super(RNN, self).call(full_input, **kwargs)
710 # Remove the additional_specs from input spec and keep the rest. It is
711 # important to keep since the input spec was populated by build(), and

/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)
225 ’ is incompatible with layer ’ + layer_name +
226 ‘: expected shape=’ + str(spec.shape) +
→ 227 ‘, found shape=’ + str(shape))

ValueError: Input 0 is incompatible with layer lstm: expected shape=(None, None, 90), found shape=[90, 1, 1]

Try restarting the kernel and running all of the cells again.

1 Like

Hi TMosh,
Tried Restart and Clear output for several times but same error is still shown.

I tried to print the shapes to trace the dimensions within the for loop in Step 2:
when t = 0,

shape of “out” is (None, 90)
shape of x after running tf.math.argmax function is (None,)
shape of x after tf.one_hot function is (None,1)
shape of x after running RepeatVector(1)(x) function is (None,1,1)

Is there any abnormal step(s)?

Hi TMosh,
I found that there is indeed wrong with the expected dimensions after reading instructions again.
Then finally the issue has been resolved by fixing tf.one_hot function parameters.