C5week1 coding 3 improvising a Jazz solo

I got this error message when running # UNIT TEST
inference_summary = summary(inference_model)
comparator(inference_summary, music_inference_model_out).
I’m not why

AttributeError Traceback (most recent call last)
----> 4 inference_summary = summary(inference_model)
5 comparator(inference_summary, music_inference_model_out)

~/work/W1A3/test_utils.py in summary(model)
34 result =
35 for layer in model.layers:
—> 36 descriptors = [layer.class.name, layer.output_shape, layer.count_params()]
37 if (type(layer) == Conv2D):
38 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)
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.

1 Like

If this hint doesn’t help, please click my name and message your notebook as an attachment.

Thanks for quick reply and I will check it out.
Also ,at a higher level, what is the purpose of building the music_inference_model()? My understanding is that it restructured the model and made the y(t-1) the input of x(t). At the same time it kept the weight and biase from the previously trained model djmodel(). Is that correct?


Your understanding is along the right track. The music generation system aims to generate the note for the next timestep with input as the note at the current timestep and the context capturing information about notes seen since the start of time.

Thanks for confirming.
I have these following questions regarding this assignment.

1)In the djmodel() why the input statement omits ‘m’ when stating the shape?
Input(shape=(Tx, n_values))

2)Why the output of reshaper() is (1, n_values)? What happened with m

3)When using TensorFlow model, does the shape of input X have to be (m, Tx, n_values), and Y ( 𝑇𝑦,𝑚,n_values)? Why they have different shapes?


Input and output of a model should be considered for a single data point. m refers to the batch dimension. Batch dimension is not mentioned to a model since it can vary across each training step. To give a concrete example, if batch size is 32 and we have 69 data points, each epoch will have 3 training steps to process batches of sizes 32, 32 and 5.

Train time:
In the assignment, input consists of Tx number of time steps. Even though you manually iterate over each timestep inside djmodel, the actual signature of the model is to accept (Tx, n_values) shaped row. As far as the model training output is concerned, the last trainable layer emits output of shape (1, n_values) per invocation.

While the trainable layer emits 1 note per input, the actual model output is a list containing (m, n_values) for each timestep taking batch dimension into consideration. Since we have Tx number of time steps, we’ve got the model to emit the eventual output of shape (Tx, m, n_values). This makes it nice for training since all we have to do is present input shifted by 1 timestep as expected output to the model. The objective is to minimize the sum of losses across all time steps.

Inference time:
We now have the base layers of the model trained to emit 1 note for Tx time steps of input. We customize the model by using these base layers and emit outputs for Ty number of time steps.

Reshaper: Each input row to the lstm should be of shape (num timesteps, num features). From X, we get access to the features for the current timestep of shape (num features, ). We use the reshaper layer to change the shape to (1 timestep, num features) ie. to add the time dimension.