I have this code to predict an image using FASTER RCNN model:
import torch
import torchvision
from torchvision import transforms as T
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained = True)
model.eval()
img = Image.open("../image.jpg")
transform = T.Compose([T.ToTensor()])
ig = transform(img).unsqueeze(0)
with torch.no_grad():
pred = model(ig)
The result of pred like that:
[{'boxes': tensor([[3.9041e+00, 3.3453e+02, 1.4249e+02, 4.0109e+02],
[7.1592e+02, 2.9045e+02, 1.0998e+03, 5.9793e+02],
[5.9441e+02, 2.3850e+02, 7.3092e+02, 5.3254e+02],]),
'labels': tensor([ 3, 3, 1]),
'scores': tensor([0.9970, 0.9961, 0.9961])}]
I want to retrieve the 'logits' for the class predictions for the Faster RCNN model in torchvision,
["logits" refers to the raw, unnormalized scores or probabilities assigned to different classes by a model. Logits are the output of the last layer of a neural network before it undergoes a normalization operation (often softmax) to produce probabilities.]
How I can do that ?
I have tried to do like that:
pred['logits'] but I got this error: 'Keyerror: 'logits''.