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

Mastering the init method

In PyTorch Lightning, the __init__ method is the heart of your LightningModule setup. It's where you define model layers, parameters, and any initial configuration before training. By cleanly separating this setup step, PyTorch Lightning makes it easier to maintain and scale your projects. In this exercise, you'll focus on initializing the class for your classification model.

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

Scalable AI Models with PyTorch Lightning

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

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

  • Create a class named ClassifierModel that inherits from pl.LightningModule.
  • Initialize the parent class to leverage LightningModule's capabilities.

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

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

import lightning.pytorch as pl
import torch.nn as nn

# Create the class
class ClassifierModel(____):
    # Create init method
    def __init__(self, input_dim, output_dim):
        ____
        self.classifier = nn.Linear(input_dim, output_dim)
कोड संपादित करें और चलाएँ