Week 1, jazz assignment music_inference_model

Hi again!

In

# UNQ_C2 (UNIQUE CELL IDENTIFIER, DO NOT EDIT)
# GRADED FUNCTION: music_inference_model

I am having a weird error. I already try restarting the kernel and so on.

i do not figure how i could change this dimensions, they (appear to me) to be outside #START-#END code requeriments.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-a33998d93c7b> in <module>
----> 1 inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)

<ipython-input-16-d7e5e3dc1955> in music_inference_model(LSTM_cell, densor, Ty)
     38     for t in range(Ty):
     39         # Step 2.A: Perform one step of LSTM_cell. Use "x", not "x0" (≈1 line)
---> 40         a, _, c = LSTM_cell(x, initial_state=[a, c])
     41 
     42         # 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)
    927 
    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))
    228 
    229 

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

UPDATE:

i note that if i execute this previous cell:

print(f"loss at epoch 1: {history.history['loss'][0]}")
print(f"loss at epoch 100: {history.history['loss'][99]}")
plt.plot(history.history['loss'])

the error from same function (even without execute the cell function again) changes to:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-a33998d93c7b> in <module>
----> 1 inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)

<ipython-input-11-d7e5e3dc1955> in music_inference_model(LSTM_cell, densor, Ty)
     38     for t in range(Ty):
     39         # Step 2.A: Perform one step of LSTM_cell. Use "x", not "x0" (≈1 line)
---> 40         a, _, c = LSTM_cell(x, initial_state=[a, c])
     41 
     42         # 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)
    927 
    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)
    156                      str(len(input_spec)) + ' inputs, '
    157                      'but it received ' + str(len(inputs)) +
--> 158                      ' input tensors. Inputs received: ' + str(inputs))
    159   for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):
    160     if spec is None:

ValueError: Layer lstm expects 5 inputs, but it received 3 input tensors. Inputs received: [<tf.Tensor 'input_3:0' shape=(None, 1, 90) dtype=float32>, <tf.Tensor 'a0_2:0' shape=(None, 64) dtype=float32>, <tf.Tensor 'c0_2:0' shape=(None, 64) dtype=float32>]

All this outputs are comming from this cell:

inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)
1 Like

In general, you have to be very careful about running just specific cells in the notebooks. This is because they can use a lot of global variables, which can be modified in unexpected ways if you don’t run the cells in the exact sequence.

1 Like

Yes, i have been trying restarting the kernell and so on.

Still same error. I have no idea why those dimensions doesnt match. Any hint?

I see you deleted your latest reply. Do you still need help with this?

I need help about the error shown below.

ValueError: Layer lstm expects 5 inputs, but it received 3 input tensors. Inputs received: [<tf.Tensor ‘input_2:0’ shape=(None, 1, 90) dtype=float32>, <tf.Tensor ‘a0_1:0’ shape=(None, 64) dtype=float32>, <tf.Tensor ‘c0_1:0’ shape=(None, 64) dtype=float32>]

The message says you’ve passed too many arguments to the LSTM layer.

It might help to see the whole exception trace. One thing to check: are you sure you used the predefined function LSTM_cell that they defined for you, instead of directly invoking LSTM yourself?

1 Like

Issue resolved . Thanks