เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Implementing the validation step

Once we trained a neural network model we need to monitor its performance during training. Using PyTorch Lightning, implement the validation_step() method to calculate and log the validation loss at each epoch.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Scalable AI Models with PyTorch Lightning

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Compute predictions using the model on input batch.
  • Calculate validation loss using F.cross_entropy().
  • Log the validation loss with self.log() as val_loss.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

import torch.nn.functional as F

def validation_step(self, batch, batch_idx):
    x, y = batch
    # Compute predictions using the model
    preds = ____(x)
    # Calculate validation loss
    loss = F.____(preds, y)
    # Log the validation loss
    self.____('val_loss', loss)
แก้ไขและรันโค้ด