Skip to content

Commit

Permalink
[Mihai Neagu][Predict] Also display probabilities for the top_k classes
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaiNeagu committed Nov 16, 2023
1 parent d770a45 commit 0b5892a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,10 @@ def predict(model, path_to_image, gpu, top_k):
idx_to_class = {v: k for k, v in model.class_to_idx.items()}

top_labels = [cat_to_name[idx_to_class[idx]] for idx in classes.cpu().numpy().tolist()[0]]

probabilities = probs.cpu().numpy()[0] * 100

print(f'Flower name: {top_labels[0]} with a probability of {probabilities[0]}')
print(f'Top {top_k} most likely classes: ', top_labels)
print(f'Top {top_k} most likely classes: ', dict(zip(top_labels, probabilities)))



Expand Down

0 comments on commit 0b5892a

Please sign in to comment.