TensorLearn
Back to Course
Deep Learning with PyTorch
Module 2 of 12

2. The nn.Module

The Blueprint

All PyTorch models inherit from nn.Module. You must define:

  1. __init__: The layers.
  2. forward: The flow of data.
python
class Net(nn.Module): def __init__(self): super().__init__() self.fc1 = nn.Linear(10, 5) def forward(self, x): return torch.relu(self.fc1(x))

Mark as Completed

TensorLearn - AI Engineering for Professionals