I am hitting this error in the Jazz music assignment . Researched the forum and tried out different stuffs. Can I please get some help in resolving this? The expected parameter goes up with every run.
**ValueError: Layer lstm expects 13 inputs, but it received 3 input tensors. Inputs received: [<tf.Tensor 'input_8:0' shape=(None, 1, 90) dtype=float32>, <tf.Tensor 'a0_7:0' shape=(None, 64) dtype=float32>, <tf.Tensor 'c0_7:0' shape=(None, 64) dtype=float32>]**
Did you try restarting the kernel and re-running all of the cells in the notebook?
I ask because in this notebook, LSTM_cell is a global instance of an LSTM layer. So any changes you make to LSTM_cell in any of the functions throughout the notebook means you have to re-run the whole notebook again.
For example:
Let’s say you modify LSTM_cell in the djmodel() function - that will impact any code in music_inference_model() that uses LSTM_cell. So you have to re-run everyrthing to get them back in sync.
LSTM_cell is created way back in Section 2 of the notebook, before you worked on djmodel().
I had tried that previously . But did that now again. I get a different error now.
ARNING:tensorflow:Functional inputs must come from `tf.keras.Input` (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "functional_3" was not an Input tensor, it was generated by layer repeat_vector_99.
Note that input tensors are instantiated via `tensor = tf.keras.Input(shape)`.
The tensor that caused the issue was: repeat_vector_99/Tile:0
WARNING:tensorflow:Functional inputs must come from `tf.keras.Input` (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "functional_3" was not an Input tensor, it was generated by layer lstm.
Note that input tensors are instantiated via `tensor = tf.keras.Input(shape)`.
The tensor that caused the issue was: lstm/PartitionedCall_129:2
WARNING:tensorflow:Functional inputs must come from `tf.keras.Input` (thus holding past layer metadata), they cannot be the output of a previous non-Input layer. Here, a tensor specified as input to "functional_3" was not an Input tensor, it was generated by layer lstm.
Note that input tensors are instantiated via `tensor = tf.keras.Input(shape)`.
The tensor that caused the issue was: lstm/PartitionedCall_129:3
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-18-fe42db94b8ce> in <module>
1 ### YOU CANNOT EDIT THIS CELL
----> 2 inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)
<ipython-input-17-73811659398b> in music_inference_model(LSTM_cell, densor, Ty)
56
57 # Step 3: Create model instance with the correct "inputs" and "outputs" (≈1 line)
---> 58 inference_model = Model(inputs=[x, a, c], outputs=outputs)
59
60 ### END CODE HERE ###
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in __new__(cls, *args, **kwargs)
240 # Functional model
241 from tensorflow.python.keras.engine import functional # pylint: disable=g-import-not-at-top
--> 242 return functional.Functional(*args, **kwargs)
243 else:
244 return super(Model, cls).__new__(cls, *args, **kwargs)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
455 self._self_setattr_tracking = False # pylint: disable=protected-access
456 try:
--> 457 result = method(self, *args, **kwargs)
458 finally:
459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in __init__(self, inputs, outputs, name, trainable)
113 # 'arguments during initialization. Got an unexpected argument:')
114 super(Functional, self).__init__(name=name, trainable=trainable)
--> 115 self._init_graph_network(inputs, outputs)
116
117 @trackable.no_automatic_dependency_tracking
/opt/conda/lib/python3.7/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
455 self._self_setattr_tracking = False # pylint: disable=protected-access
456 try:
--> 457 result = method(self, *args, **kwargs)
458 finally:
459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in _init_graph_network(self, inputs, outputs)
182 # It's supposed to be an input layer, so only one node
183 # and one tensor output.
--> 184 assert node_index == 0
185 assert tensor_index == 0
186 self._input_layers.append(layer)
AssertionError:
Thank you @TMosh that helped clearing all Unit tests .
Now in the predict_and_sample function I hit the below error and running out of ideas.
shape of pred - (1, 90)
shape of indices - (1,)
shape of results - (1, 90)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-65-0bfb6bdfdaab> in <module>
3 results, indices = predict_and_sample(inference_model, x_initializer, a_initializer, c_initializer)
4
----> 5 print("np.argmax(results[12]) =", np.argmax(results[12]))
6 print("np.argmax(results[17]) =", np.argmax(results[17]))
7 print("list(indices[12:18]) =", list(indices[12:18]))
IndexError: index 12 is out of bounds for axis 0 with size 1```
This is how I process indices ,I suspect the shape of indices is incorrect for some reason.
@TMosh I was able to resolve the error. There was a issue in the definition of music_inference_model which I had to fix . Interestingly I had "All tests passed " for music_inference_model even with that issue.