Skip to content

Fix: Add required 'task' and 'num_classes' to torchmetrics.Accuracy - #1353

Open
FrankieLiuF wants to merge 1 commit into
mrdbourke:mainfrom
FrankieLiuF:main
Open

Fix: Add required 'task' and 'num_classes' to torchmetrics.Accuracy#1353
FrankieLiuF wants to merge 1 commit into
mrdbourke:mainfrom
FrankieLiuF:main

Conversation

@FrankieLiuF

Copy link
Copy Markdown

Description

This PR fixes a TypeError that occurs when running the code due to an API change in newer versions of torchmetrics (>= 1.0.0), where the task parameter is now required.

The error was:
TypeError: Accuracy.new() missing 1 required positional argument: 'task'

Solution

Added task="multiclass" and num_classes=4 to the Accuracy initialization.

# Before
torchmetric_accuracy = Accuracy().to(device)

# After
torchmetric_accuracy = Accuracy(task="multiclass", num_classes=4).to(device)

Context

The num_classes=4 is based on the specific dataset being used in this project.
I have tested this locally and it resolves the runtime error.

Checklist

  • Code compiles correctly
  • Changes tested locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant