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
ClassifierModelthat inherits frompl.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)