How to calculate the percentage of which kind the given image is after machine learning in pytorch?
I trained my machine with custom vgg model with CIFAR10 data set, and tested with some images in same data set.
airplane :  -16.972412
automobile :  -18.719894
bird :  -6.989656
cat :  -3.8386667
deer :  -7.622768
dog :  0.37765026
frog :  -8.165334
horse :  -7.4519434
sheep :  -21.241518
truck :  -18.978928

This is one of how I got the value of what kind the test image is. Below is what I implemented to print above:
kind = [&quot;airplane&quot;, &quot;automobile&quot;, &quot;bird&quot;, &quot;cat&quot;, &quot;deer&quot;, &quot;dog&quot;, &quot;frog&quot;, &quot;horse&quot;, &quot;sheep&quot;, &quot;truck&quot;]
for k in kind:
      print(k,&quot;: &quot;, output.cpu().detach().numpy()[0][kind.index(k)])

Here, it is correct that given test image is dog, which is the highest value, yet I want to print every values as percentage, which the sum of all is 100. How could I do this? I used pytorch for code.

These values are logits, you should apply softmax on them to get the probability values between 0 - 1 and then you can multiply them by 100.
Code Snippet:
pred = output.cpu().detach().numpy()

def softmax(x):
  &quot;Function computes the softmax values for the each element in the given numpy array&quot;
  return np.exp(x) / np.sum(np.exp(x), axis=0)

def probability(x):
  &quot;Function applies softmax for the given logit and returns the classification probability&quot;
  return softmax(x) * 100

output_probs = probability(preds)

or you can use softmax function from scipy
from scipy.special import softmax

output_probs = softmax(preds)

