Skip to content

is there any way to get confidence score for prediction #587

Answered by amaarora
AnhMinhTran asked this question in Q&A
Discussion options

You must be logged in to vote

If I understand your question correctly, I think if you're doing classification, all you pretty much need to do is add a nn.Softmax() layer on top of the a trained model.

So consider you do something like:

import torch 
import timm 
import torch.nn as nn


class ProbabilityModel(nn.Module):
    def __init__(self, model_name, **kwargs):
        super().__init__()
        self.model = timm.create_model(model_name, **kwargs)
        self.softmax = nn.Softmax()

    def forward(self, x):
         out = self.model(x)
         probabilities = self.softmax(out)
         return probabilities

# random input image
x = torch.randn(1, 3, 224, 224)
m = ProbabilityModel('resnet34', pretrained=True, nu…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by AnhMinhTran
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants