How to see classification probabilities in the object detection

currently, working on object detection model, I have built the model using Faster RCNN with ResNet50 as backbone and I have 4 target classes. Now, I would like to see the class probabilities while inferencing.
eg: 4 classes[car, person, truck, train], when I pass the truck image in the model, it gives me output with bbox, predicted class(truck) and confidence score. How can I get the class probability [0.2, 0,0.75, 0.05].

For ‘car’ its probability is 0.2
For ‘person’ its probability is 0
For ‘truck’ its probability is 0.75
For ‘train’ its probability is 0.05

Has anyone tried this? any articles or example script would help me to replicate the same.
Thanks in advance.

Normally, probability-like predictions over multi classes from a classification model is softmax result for each elements in prediction vector. You could pass the predictions into softmax and get probabilities.

@bigbreadguy, I’m using inbuilt fasterrcnn detector from pytorch. I want the extract the last layer from it. can you provide me any suggestion how to do that?

You can iterate through layers(modules, strictly) in the model.

Please refer to attached scripts.

My bad.

You need to entangle the layers as built-in methods like this.

Hey @bigbreadguy and @iamexperimentingnow
I tried following your steps but couldn’t reach the wanted results… Any update on this?