Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing predictions #66

Open
Aishaj opened this issue Aug 6, 2021 · 1 comment
Open

Printing predictions #66

Aishaj opened this issue Aug 6, 2021 · 1 comment

Comments

@Aishaj
Copy link

Aishaj commented Aug 6, 2021

Hi,

I'm trying to print the prediction results and the labels, in addition to accuracy.
I;m not sure what I'm doing wrong here

for mfcc, label in test_data:
prediction = tflite_inference(mfcc, tflite_path)
predicted_indices.append(np.squeeze(tf.argmax(prediction, axis=1)))

strlabel="C:/tmp/speech_commands_train/conv_labels.txt"
labels_list= [line.rstrip() for line in tf.io.gfile.GFile(strlabel)]

top_k = prediction.argsort()[-5:][::-1]


for node_id in top_k:
 human_string = labels_list[node_id]
 score = predicted_indices[node_id]
print('%s (score = %.5f)' % (human_string, score))

test_accuracy = calculate_accuracy(predicted_indices, expected_indices)
confusion_matrix = tf.math.confusion_matrix(expected_indices, predicted_indices,
                                            num_classes=model_settings['label_count'])

Error message

human_string = labels_list[node_id] TypeError: only integer scalar arrays can be converted to a scalar index

Thank you in advance for your help.

@Burton2000
Copy link
Contributor

From the error message you are trying to index into a list using something that is not an integer.

You need to check what top_k is, it looks like it might be some multi-dimensional array which you can't use to index into labels_list. Or alternatively it could be that the data shapes are okay but the type is wrong, you might need to cast the data from float to int to index into labels_list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants