I need to get labels from validation dataset for construct the confusion matrix, but I can't get labels with normal order without recreating the dataset with disabled the shuffle. Any idea? Probably, there are any ways to get prediction together with labels? (how is, model.evaluate() works with shuffle)
Asked
Active
Viewed 523 times
1 Answers
1
ok, I found the answer: Getting true labels for keras predictions
for images, labels in val_ds:
preds = model.predict(images)
acc_sc = acc(labels, tf.argmax(preds, axis=1))
print(acc_sc)
break # or accumulate and average score from all batches
But probably a better way is exist?

Dmitry Sokolov
- 1,303
- 1
- 17
- 29
-
That's still shuffled – Nicolas Gervais Apr 02 '22 at 13:03
-
yes, but you can calculate accuracy from each batch and average it. – Dmitry Sokolov Apr 02 '22 at 13:06
-
that doesn't answer the title of your question, and if your answer is the same as the other question, your question will be closed as duplicate – Nicolas Gervais Apr 02 '22 at 15:26