I am not able to get the music_inference_model(LSTM_cell, densor, Ty=100) work as it is supposed to. I had worked on it for a couple of hours, but I could not find a way around it that everything goes safe and sound. To be more specific, I need guidance regarding the proper implementation of the part referred to as 2.D. This is the error that I stuck with:
AttributeError: The layer “lstm” 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 do not post my code snippet, as I think it is against the moral code, however, let me know if it is required.
In the loop you are asked to update the cell state (initialized with a0 and c0) for every time period. That gives you the x and the updated a and c values inside the LSTM cell. Then the state variable that is passed between the LSTM cells at different time periods is also fed to the densor. I think if you do this your output should be correct.
Hi laacdm, thanks for your reply, however, I don’t think the problem is what you addressed. As I mentioned earlier, it seems that my problem lies in the implementation of the 2.D, which consists of two substeps; using the tf.math.argmax() function to get the index of the maximum value of the x and consecutively, converting the x to an one_hot representation, using the tf.one_hot(). I believe I am not using the tf.one_hot() function correctly and I tried to find more supplementary information regarding using it, but I found them somehow complicated. Please let me know if you have a fairly straightforward explanation regarding this function and the way it is supposed to be used.
If your tf.math.argmax() part is correct then the instructions tell you to use the results of it as one of the arguments in the tf.one_hot() function the other argument should be the shape of input values. After that you have still to add one more layer. As a hint look at which of the keras layers imported at the beginning of the notebook you have not used up to this point and its respective documentation.
I passed the output of the tf.math.argmax() as the indices argument of the tf.one_hot() and I took the n_values declared earlier in the same cell as the depth argument of the tf.one_hot() function, but I don’t know what is the problem. The error is generated by the execution of the first unit test, after the music_inference_model() function, when the inference_summary = summary(inference_model) is being executed.
Dear laccdm, I have read both instructions and your comment carefully and I believe you are addressing the use of the RepeatVector(), which is the 2.E step of this exercise and I had taken care of that before.
I was wondering if you could check my code, as it is almost two days now that I am stuck with this error.
You have to give to the argmax function the axis to reduce across (which is the last dimension). If you print the shape of a you will see that the second dimension is None and so you want to drop it.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-80-c395f100af16> in <module>
1 # UNIT TEST
----> 2 inference_summary = summary(inference_model)
3 comparator(inference_summary, music_inference_model_out)
~/work/W1A3/test_utils.py in summary(model)
33 result = []
34 for layer in model.layers:
---> 35 descriptors = [layer.__class__.__name__, layer.output_shape, layer.count_params()]
36 if (type(layer) == Conv2D):
37 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)
2193
2194 @property
AttributeError: The layer "lstm" 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.
… but shapes looks well:
x.shape after argmax: (None,)
x.shape after one_hot: (None, 90)
x.shape after RepeatVector: (None, 1, 90)
Do you have any idea where i can check for an error?
Thank you!
Hi Leszek. My mistake was not using the tf.argmax() properly, you may consider checking that line. You can also read the comments left by laacdm, especially the ones that are written almost two days ago, as they are sufficient intitutive.
I have the same problem as Leszek and I am using the last axis in the argmax function. x shapes are as follows:
x.shape after argmax: (None,)
x.shape after one_hot: (None, 90)
x.shape after RepeatVector: (None, 1, 90)
I had the same problems. All recommendations here are very useful. The last one, restarting the kernel and running again all cells, is necessary after many changes. Thanks.