[PyTorch] TypeError: accuracy() missing 1 required positional argument: 'task'

MINSEO KIM·2025년 3월 12일
0

error

목록 보기
2/2

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)

Related Docs

Accuracy — PyTorch-Metrics 1.6.2 documentation

0개의 댓글