Aan de slagGa gratis aan de slag

Calculating accuracy using torchmetrics

Tracking accuracy during training helps identify the best-performing epoch.

In this exercise, you'll use torchmetrics to calculate accuracy on a facemask dataset with three classes. The plot_errors function will highlight misclassified samples, helping you analyze model errors.

torchmetrics package is already imported. Model outputs are softmax probabilities, and labels are one-hot encoded vectors.

Deze oefening maakt deel uit van de cursus

Introduction to Deep Learning with PyTorch

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create accuracy metric
metric = torchmetrics.____(____, ____)
for features, labels in dataloader:
    outputs = model(features)
  
    # Calculate accuracy over the batch
    metric.____(____, ____)
Code bewerken en uitvoeren