Skip to content

Section 02: Facing the error TypeError: __new__() missing 1 required positional argument: 'task' #318

Answered by mrdbourke
karthikbhandary2 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @karthikbhandary2,

Good question!

There's been an update to TorchMetrics since the video was recorded.

Please see the fix here: #200 (comment)

Or alternatively, you can try:

try:
    from torchmetrics import Accuracy
except:
    !pip install torchmetrics==0.9.3 # this is the version we're using in this notebook (later versions exist here: https://torchmetrics.readthedocs.io/en/stable/generated/CHANGELOG.html#changelog)
    from torchmetrics import Accuracy

# Setup metric and make sure it's on the target device
torchmetrics_accuracy = Accuracy(task='multiclass', num_classes=4).to(device)

# Calculate accuracy
torchmetrics_accuracy(y_preds, y_blob_test)

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@karthikbhandary2
Comment options

Answer selected by karthikbhandary2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants