From 0b5892a8e9aeb71f54085184428ac56bb06799f4 Mon Sep 17 00:00:00 2001 From: Mihai Neagu Date: Fri, 17 Nov 2023 01:23:38 +0200 Subject: [PATCH] [Mihai Neagu][Predict] Also display probabilities for the top_k classes --- model_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/model_utils.py b/model_utils.py index 124312bd..6aa03c55 100644 --- a/model_utils.py +++ b/model_utils.py @@ -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)))