C5 W1 Program 3 - predict error

Hi,

I am getting an error on the final function in the Jazz exercise. Not sure what the problem is. I changed the axis to be 0 and still the same error.

Thank you for any help.

Neil

n_values = x_initializer.shape[2]

Step 1:

pred = inference_model([x_initializer, a_initializer, c_initializer])

Step 2:

indices = np.argmax(pred, axis=-1)

Step 3:

results = to_categorical(indices, num_classes=x_initializer.shape[2])

return results, indices

I
ndexError Traceback (most recent call last) in 1 results, indices = predict_and_sample(inference_model, x_initializer, a_initializer, c_initializer) 2 ----> 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])) IndexError: index 12 is out of bounds for axis 0 with size 1

1 Like

In step 3, try num_classes = n_values.

Screenshot 2021-11-26 at 7.35.39 AM

@Anri_Lombard,
n_values isn’t a global variable. It’s set by this line earlier in the function:

n_values = x_initializer.shape[2]

The solution to the student’s problem was not posted on the forum. I think the student’s original code would have worked fine, and the error was probably somewhere else. In any case, the “results” variable did not have 12 elements, that’s what triggered the error.

Hi, I seem to be having this problem as well. I’m not sure what I should be looking for?

Hi @0rb ,

This thread is 3 years old, please start a fresh query with error output for a speedy response.

1 Like