JimLee1996 / AVSS2019

Efficient Violence Detection Using 3D Convolutional Neural Networks
MIT License
15 stars 10 forks source link

How to get the right violence probability #2

Open bilel-bj opened 4 years ago

bilel-bj commented 4 years ago

Thanks again for your consideration and support. How can I get the right violence probability instead of boolean value in the function predict:

    def predict(self, x):
        x = x.to(self.device)
        # need N x C x T x H x W
        if len(x.shape) < 5:
            x = x.unsqueeze(0)
        y = self.net(x)

        _, results = y.topk(1, 1, True)

        labels = ['normal' if x else 'violent' for x in results]

        return labels

It is more accurate to estimate the right probability of having violence in the video rather than getting boolean value.

JimLee1996 commented 4 years ago

print(y)

bilel-bj commented 4 years ago

Thank you. This is what it returns to me. How to read these values.

print(y)
tensor([[ 1.9981, -1.9514]], device='cuda:0', grad_fn=<AddmmBackward>)
JimLee1996 commented 4 years ago

Since we adopt CELoss(https://pytorch.org/docs/stable/nn.html#torch.nn.CrossEntropyLoss), the output value is not probability. However, you can utilize the signs and abs() values to evaluate how sure the model is about this category.

bilel-bj commented 4 years ago

Thanks for your reply. Do you know the equations how to convert these two value[ 1.9981, -1.9514] into 1 value predicting the violence probability ?

JimLee1996 commented 4 years ago

Try SoftMax. Please inform me if it is feasible.

exp(1.9981)/(exp(1.9981)+exp(-1.9514))=0.98?

bilel-bj commented 4 years ago

Thanks for your reply. I added these two lines of codes and it works fine:

        sm = torch.nn.Softmax()
        probabilities = sm(y)