0
0
PyTorchml~5 mins

Batch normalization (nn.BatchNorm) in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of batch normalization in neural networks?
Batch normalization helps to stabilize and speed up training by normalizing the inputs of each layer, keeping their mean close to 0 and variance close to 1.
Click to reveal answer
intermediate
How does nn.BatchNorm1d differ from nn.BatchNorm2d in PyTorch?
nn.BatchNorm1d is used for 2D inputs like (batch_size, features), often in fully connected layers, while nn.BatchNorm2d is for 4D inputs like (batch_size, channels, height, width), used in convolutional layers.
Click to reveal answer
beginner
What are the two main parameters learned by batch normalization layers?
Batch normalization layers learn two parameters: gamma (scale) and beta (shift), which allow the network to adjust normalized outputs if needed.
Click to reveal answer
intermediate
Why is batch normalization usually turned off during model evaluation?
During evaluation, batch normalization uses running estimates of mean and variance instead of batch statistics to ensure consistent outputs for single samples.
Click to reveal answer
beginner
Show a simple PyTorch example of applying nn.BatchNorm1d to a tensor of shape (batch_size=4, features=3).
import torch
import torch.nn as nn

x = torch.randn(4, 3)  # random input
batch_norm = nn.BatchNorm1d(3)  # 3 features
output = batch_norm(x)
print(output)

# This normalizes each feature across the batch.
Click to reveal answer
What does batch normalization normalize in a neural network?
AThe loss function
BThe outputs of the entire network
CThe weights of the network
DThe inputs to each layer
Which PyTorch class is used for batch normalization on 2D convolutional outputs?
Ann.BatchNorm1d
Bnn.LayerNorm
Cnn.BatchNorm2d
Dnn.BatchNorm3d
What are the learnable parameters in a batch normalization layer?
AGamma (scale) and beta (shift)
BWeights and biases
CMean and variance
DLearning rate and momentum
Why do we use running mean and variance during evaluation in batch normalization?
ATo avoid using batch statistics which may vary
BTo speed up training
CTo increase model complexity
DTo reduce model size
What happens if you forget to call model.eval() before evaluation when using batch normalization?
AModel runs faster
BBatch normalization uses batch statistics, causing inconsistent outputs
CWeights stop updating
DNothing changes
Explain in simple terms how batch normalization helps neural networks learn better.
Think about how keeping data stable helps learning.
You got /5 concepts.
    Describe the difference between training and evaluation modes for batch normalization in PyTorch.
    Consider what changes when you switch from training to testing.
    You got /4 concepts.