'torchmetrics behaviour for one-hot encoded values

I am having a hard time understanding the following scenario. I have a output probability of 0.0 on each class which means value of metrics such as f1 score, accuracy and recall should be zero? However i get the following:

import torch, torchmetrics
preds = torch.tensor([[0., 0., 0.],
                      [0., 0., 0.],
                      [0., 0., 0.]])

target = torch.tensor([[1, 0, 0],
                       [0, 1, 0],
                       [0, 0, 1]])

print("F1: ", torchmetrics.functional.f1_score(preds, target))
print("Accuracy: ", torchmetrics.functional.accuracy(preds, target))
print("Recall: ", torchmetrics.functional.recall(preds, target))
print("Precision: ", torchmetrics.functional.precision(preds, target))

Output:

F1:  tensor(0.)
Accuracy:  tensor(0.6667)
Recall:  tensor(0.)
Precision:  tensor(0.)

Why is accuracy 0.6667? I would expect all outputs to be 0.0.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source