BaşlayınÜcretsiz Başlayın

Evaluate model accuracy using Torchmetrics

Evaluating how well your model performs is essential - especially when preparing it for deployment! Let's smoothly integrate accuracy calculation using Torchmetrics right into the validation_step(). Don't forget to log the results, so you can easily monitor your model's progress.

Bu egzersiz

Scalable AI Models with PyTorch Lightning

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import Accuracy from torchmetrics.
  • Instantiate the accuracy metric inside __init__().
  • Calculate accuracy within validation_step() and log it as 'val_acc'.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Import relevant metric
from torchmetrics import ____
import lightning.pytorch as pl

class ClassifierModel(pl.LightningModule):
    def __init__(self):
        super().__init__()
        # Instantiate accuracy metric
        self.accuracy = ____()
    def validation_step(self, batch, batch_idx):
        x, y = batch
        preds = self(x)
        # Calculate accuracy and log it as val_acc
        acc = self.____(preds, y)
        self.log(____, acc)
Kodu Düzenle ve Çalıştır