How to compute accuracy when using v2.Mixup?

Hi all,

In the context of v2.Mixup, how would one go about calculating accuracy when ‘lambda,’ target_a, and target_b are not returned?

The original implementation involves accuracy calculation by multiplying with ‘lambda’ and comapring predictions with target, summing the results together (below):

        correct += (lam * predicted.eq(
                    + (1 - lam) * predicted.eq(

But v2.MixUp(num_classes=NUM_CLASSES) does not return these values.

Thanks a lot.

from torchvision.transforms import v2
from import DataLoader


dataloader = DataLoader(dataset, batch_size=4, shuffle=True)

mixup = v2.MixUp(num_classes=NUM_CLASSES)

for images, labels in dataloader::
            inputs =
            targets = labels .to(device)

            # zero the parameter gradients

            # forward
            # track history if only in train
            with torch.set_grad_enabled(True):
                outputs = model(inputs)
                loss = criterion(outputs, targets)   # where criterion = nn.CrossEntropyLoss()

                # backward + optimize

            # statistics
            train_loss += loss.item()

            # acc =??