Error message
----> 5 acc = torchmetrics.functional.accuracy(preds, target)
TypeError: accuracy() missing 1 required positional argument: 'task'
python==3.8.18
torch==2.4.1
Solution
- I was learning with a YouTube video & He used the code below
preds = torch.rand(10, 5).softmax(dim=-1)
target = torch.randint(5, (10, ))
print(preds, target)
acc = torchmetrics.functional.accuracy(preds, target)
print(acc)
- However, in the version I use, the user should specify
task
: 'multiclass', 'binary'
- It was just a test so I used the code below
preds = torch.rand(10, 5)
target = torch.zeros(5)
print(preds)
print(target)
acc = torchmetrics.functional.accuracy(preds[0], target, task='binary')
print(acc)
Accuracy — PyTorch-Metrics 1.6.2 documentation