I am stuck on this exercise from last 2 weeks and missed the deadline twice.
In the function def music_inference_model, I am getting this error.
TypeError Traceback (most recent call last)
in
1 ### YOU CANNOT EDIT THIS CELL
----> 2 inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)
in music_inference_model(LSTM_cell, densor, Ty)
51
52 x = tf.math.argmax(outputs)
—> 53 x = tf.one_hot(x)
54 # Step 2.E:
55 # Use RepeatVector(1) to convert x into a tensor with shape=(None, 1, 90)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”“”
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
ValueError Traceback (most recent call last)
in
1 ### YOU CANNOT EDIT THIS CELL
----> 2 inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)
in music_inference_model(LSTM_cell, densor, Ty)
54 # Step 2.E:
55 # Use RepeatVector(1) to convert x into a tensor with shape=(None, 1, 90)
—> 56 x = RepeatVector(1)(x)
57
58 # Step 3: Create model instance with the correct “inputs” and “outputs” (≈1 line)
/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)
178 ‘expected ndim=’ + str(spec.ndim) + ‘, found ndim=’ +
179 str(ndim) + '. Full shape received: ’ +
→ 180 str(x.shape.as_list()))
181 if spec.max_ndim is not None:
182 ndim = x.shape.ndims
ValueError: Input 0 of layer repeat_vector is incompatible with the layer: expected ndim=2, found ndim=3. Full shape received: [None, 90, 90]
Ok, that is why it fails. Now you need to figure out why that happened. One possibility is that the input to the one hot function is the wrong shape. I added more print statements to my code to show the shapes at each stage of the computation:
out.shape before arg_max (None, 90)
x.shape before one_hot (90,)
x.shape after one_hot (90, 90)
x.shape after RepeatVector (90, 1, 90)
Where do yours differ? Then you need to figure out why. This is how debugging works: one step at a time.
Are you sure you specified the axis on the argmax? And that you used TensorFlow argmax, not numpy argmax? With axis = -1 on the tf.argmax, I get this:
out.shape before arg_max (None, 90)
x.shape before one_hot (None,)
x.shape after one_hot (None, 90)
x.shape after RepeatVector (None, 1, 90)
So I think what I showed earlier was actually incorrect. The “None” is the “samples” dimension there. I’m guessing maybe you used numpy argmax and specified keepdims.