I’m on a phone right now so I can’t give you code, but predict returns a tuple of class, label, probabilities (for all classes).
There’s bound to be a very easy way to zip and sort your fruit classes with the probs from predict but right now I’ve barely got enough signal to post.
Thanks so much. That’s what i thought too. But i can’t seem to figure out how to extract the probabilities from the tuple. If you could post code whenever you get access to your pc then that’d be great.
I’ll also try it on my end. And if i do accomplish it then i’ll post the code here too. thanks
There’s a very convenient method to get the top 5 confidences and their respective indices from the learn.predict output tuple
I used the following code to first get the prediction tuple
pred_class, pred_idxs, outputs = learn.predict(img2)
top_5_conf, i = outputs.topk(5)
The key to everything here is the topk function. It comes with pytorch tensors. Since outputs was a tensor the topk function could be used to get the top 5 confidences and their respective indices. The said indices can then be cross referenced with the classes list.For Example:
itr = 0
classes = data.classes
for x in i:
print(classes[x.item()], top_5_conf[itr].item())
itr=itr+1
This will print your top 5 confidences and their respective labels. Kudos and Thanks
This was the approach i was going for initially. It makes sense. Until i discovered that tensor objects in pytorch have the topk() function.
Thanks for the help @joedockrill