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.
This exercise is part of the course
Introduction to Deep Learning with PyTorch
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create accuracy metric
metric = torchmetrics.____(____, ____)
for features, labels in dataloader:
outputs = model(features)
# Calculate accuracy over the batch
metric.____(____, ____)