Prediction probabilities for on single images

I am running fastai form command line and remote script. I have it so you are able to upload the image and it will give you the prediction of what is is. It is working, but I also like the probability (how sure it is) in a percentage (80%, 0.8004, etc).

Code for testing image:

img = open_image('path/to/image/thisImg.jpg')
test = learn.predict(img)
print(test)

Reslults:

(Category Bombay, tensor(3), tensor([2.5769e-03, 8.5283e-05, 1.6160e-05, 9.2922e-01, 1.4029e-02, 8.8343e-04,
        5.3831e-03, 9.9650e-05, 9.8052e-07, 3.5275e-03, 8.1021e-05, 2.2179e-04,
        2.1642e-04, 3.5841e-04, 7.6944e-04, 1.3570e-03, 1.8250e-03, 1.4432e-03,
        1.4871e-05, 1.4886e-04, 4.0737e-03, 5.3788e-05, 5.3145e-04, 2.1978e-04,
        1.7076e-04, 3.7747e-04, 7.6558e-03, 4.2412e-03, 3.8936e-03, 2.1857e-03,
        2.7499e-04, 1.7327e-03, 1.0989e-04, 1.2305e-03, 2.5433e-03, 7.9605e-03,
        4.8365e-04]))

Thanks in advanced…

That very long tensor is the probabilities. Index into it with the second result (that tensor(2)) and it will point to what value it was.

exactly how would you do that???

1 Like

Ok, Think I under stand…

only question is, does the index number start with 0 or 1

1.6160e-05 => 0.000016160
9.2922e-01 => 0.92922

Thinking the index count/number starts with 0 which would be 0.92922 (93%) sure…

Correct?