tensorflow / tensorflow/datasets
Keras tensorflow : Get predictions and their associated ground truth labels after model.evaluate() or model.predict()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 1.6k
- Avg merge
- 3h 54m
- Merged PRs (30d)
- 1
Description
I am new to Tensorflow and Keras so the answer is perhaps simple, but I have a batched and prefetched tensorflow dataset (of type tf.data.TFRecordDataset) which consists in images and their label (int type) , and I apply a classification model on it.
`y_pred = model.predict(tf_test_dataset)`
I would like to compare classification results from ground truth for each image and put this in a dictionary. To do that I tried to create this dictionary with y_pred for each image, and its Ground truth label :
iterator = iter(tf_test_dataset)
result_dict = {}
for image_number in range(len(y_pred)):
result_dict[image_number]= \
{
"Score": y_pred[i],
"GroundTruth": iterator.get_next()[1].numpy()
}
But I am not sure if it is the right way to get predictions and their associated ground truth label. (Is it easier using model.evaluate ?). Moreover when I do
iterator = iter(tf_test_dataset)
print(iterator.get_next()[1].numpy())
and
for i in tf_test_dataset:
print(i[1].numpy())
the results (the lists with the labels) are different...
Thanks for your help
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shown tf_test_dataset iteration and model.predict() calls; determine why labels differ between iterator.get_next() and the for loop, and how predictions should be paired with labels. Done when the issue explains a reproducible way to align each prediction with its ground-truth label, including whether model.evaluate() addresses that need.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- data, machine-learning
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100