Exercise

Calculating accuracy using torchmetrics

In addition to the losses, you should also be keeping track of the accuracy during training. By doing so, you will be able to select the epoch when the model performed the best. In this exercise, you will practice using the torchmetrics package to calculate the accuracy. You will be using a sample of the facemask dataset. This dataset contains three different classes. The plot_errors function will display samples where the model predictions do not match the ground truth. Performing such error analysis will help you understand your model failure modes.

The torchmetrics package is already imported. The model outputs are not probabilities (softmax was not applied). The labels tensor contains the labels as one-hot encoded vectors.

Instructions 1/2

50 XP
    1
    2
  • Create an accuracy metric for a "multiclass" problem with three classes.
  • Calculate the accuracy for each batch of the dataloader.