Week 1, Assignment 2, Jazz, predict_and_sample

Hi guys,

I got this type of error after running the function predict_and_sample.

I guess the problem with indices, but I’ve tried axis=0, -1, 1, 2, and all of theses got me an error.

I should mention that before this cell I have no error.

ValueError Traceback (most recent call last)
----> 1 results, indices = predict_and_sample(inference_model, x_initializer, a_initializer, c_initializer)
3 print(“np.argmax(results[12]) =”, np.argmax(results[12]))
4 print(“np.argmax(results[17]) =”, np.argmax(results[17]))
5 print(“list(indices[12:18]) =”, list(indices[12:18]))

in predict_and_sample(inference_model, x_initializer, a_initializer, c_initializer)
24 pred = inference_model.predict([x_initializer, a_initializer, c_initializer])
25 # Step 2: Convert “pred” into an np.array() of indices with the maximum probabilities
—> 26 indices = np.argmax(pred, axis=-1)
27 # Step 3: Convert indices to one-hot vectors, the shape of the results should be (1, )
28 results = to_categorical(indices, num_classes=n_values)

<array_function internals> in argmax(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in argmax(a, axis, out)
1185 “”"
→ 1186 return _wrapfunc(a, ‘argmax’, axis=axis, out=out)

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
56 bound = getattr(obj, method, None)
57 if bound is None:
—> 58 return _wrapit(obj, method, *args, **kwds)
60 try:

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
45 except AttributeError:
46 wrap = None
—> 47 result = getattr(asarray(obj), method)(*args, **kwds)
48 if wrap:
49 if not isinstance(result, mu.ndarray):

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

1 Like

Try resetting the kernel and re-running all of the cells in the notebook.
Then verify that every output cell passes all of the unit tests.

I did this many times dear but I still have this error!!
I just realized that there is still test_utils.py instead of public_tests.py though I refresh the Lab. do you have any idea?

Oh, apparently I got this error after running the cell


inference_summary = summary(inference_model)
comparator(inference_summary, music_inference_model_out)

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

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

The “multiple inbound nodes” error has a lot of different causes. Search the Forum for that phrase, and you will find a lot of suggestions.

New versions of the notebook do not necessarily delete old files you still had in your workspace.

Thanks, I’ll try it.

How it goes afterwards? I got the same error.