शुरू करेंमुफ़्त में शुरू करें

Splitting data with LightningDataModule

You will complete the setup method in a LightningDataModule. Proper dataset partitioning ensures that the model is trained on one subset and validated on another, preventing overfitting.

The dataset has already been pre-imported.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Scalable AI Models with PyTorch Lightning

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Import random_split to split the dataset into training and validation.
  • Split the dataset into training (80%) and validation (20%) using random_split.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Import libraries 
import lightning.pytorch as pl
from torch.utils.data import ____

class SplitDataModule(pl.LightningDataModule):
    def __init__(self):
        super().__init__()
        self.train_data = None
        self.val_data = None
    def setup(self, stage=None):
        # Split the dataset into training (80%) and validation (20%)
        self.____, self.____ = random_split(dataset, [____, ____])
कोड संपादित करें और चलाएँ