Recall & Review
beginner
What is the purpose of the
__init__ method in a PyTorch layer class?The
__init__ method sets up the layer by defining its parameters and sub-layers. It prepares the layer to be used later in the forward pass.Click to reveal answer
beginner
Why do we call
super().__init__() inside the __init__ method of a PyTorch layer?Calling
super().__init__() initializes the parent class nn.Module, which is necessary for PyTorch to track parameters and manage the layer properly.Click to reveal answer
beginner
How do you define a fully connected layer inside the
__init__ method?You create an instance of
nn.Linear with input and output sizes, for example: self.fc = nn.Linear(input_size, output_size).Click to reveal answer
intermediate
What happens if you forget to call
super().__init__() in your layer's __init__?PyTorch will not properly register the layer's parameters, which can cause errors during training or the model not learning correctly.
Click to reveal answer
beginner
Can you store multiple layers inside the
__init__ method? How?Yes, you can define multiple layers as attributes, for example:
self.conv1 = nn.Conv2d(...) and self.fc1 = nn.Linear(...). This organizes the model parts clearly.Click to reveal answer
What is the first thing you should do inside the
__init__ method of a PyTorch layer?✗ Incorrect
Calling
super().__init__() initializes the base nn.Module class, which is essential for the layer to work properly.How do you define a linear layer with 10 inputs and 5 outputs inside
__init__?✗ Incorrect
The first argument is input size (10), the second is output size (5) for nn.Linear.
What happens if you do not call
super().__init__() in your layer?✗ Incorrect
Without calling
super().__init__(), PyTorch cannot track parameters, causing training issues.Where do you define the layers like convolution or linear in a PyTorch model?
✗ Incorrect
Layers are defined in
__init__ so they are created once and reused during forward passes.Can you define multiple layers inside
__init__?✗ Incorrect
You can define many layers as attributes like
self.conv1, self.fc1, etc.Explain the role of the
__init__ method when creating a custom PyTorch layer.Think about what happens before the model processes data.
You got /4 concepts.
Describe what could go wrong if you forget to call
super().__init__() in your PyTorch layer's __init__.Consider how PyTorch manages model parts internally.
You got /4 concepts.