is there any way to get confidence score for prediction #587
Answered
by
amaarora
AnhMinhTran
asked this question in
Q&A
-
Question as per title, with model trained through timm, is there any way to check for confidence score where top 5 add up to 1.0? |
Beta Was this translation helpful? Give feedback.
Answered by
amaarora
Apr 27, 2021
Replies: 2 comments
-
If I understand your question correctly, I think if you're doing classification, all you pretty much need to do is add a 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, num_classes=5)
m(x)
>> torch.tensor([[0.1633, 0.1588, 0.2028, 0.2260, 0.2491]], grad_fn=<SoftmaxBackward>) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
AnhMinhTran
-
Or rather you could just do,
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: