Skip to content
Discussion options

You must be logged in to vote

The dimension mismatch error occurs because the MulticlassAccuracy metric expects predictions (preds) and targets to have matching sample dimensions, but your input has a sequence length dimension that causes shape misalignment internally.
Your preds tensor is shaped (batch_size, num_classes, sequence_length) and targets (batch_size, sequence_length). TorchMetrics expects the samples dimension (batch + any extra dims) to be flattened while keeping classes as a separate dimension.
The fix is to flatten the batch and sequence length dimensions together for both preds and targets before passing them to MulticlassAccuracy. Here is the corrected code:

import torch
from torchmetrics.classification

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants