![]() |
VOOZH | about |
Batch normalization is a technique used to improve the training of deep neural networks by stabilizing the learning process. It addresses the issue of internal covariate shift where the distribution of each layer's inputs changes during training as the parameters of the previous layers change..
Batch Normalization in CNN addresses several challenges encountered during training.
Batch normalization works in convolutional neural networks (CNNs) by normalizing the activations of each layer across mini-batch during training. The working is discussed below:
In a CNN, each layer receives inputs from multiple channels (feature maps) and processes them through convolutional filters. Batch Normalization operates on each feature map separately, normalizing the activations across the mini-batch.
During training, batch normalization (BN) regularizes the activations of each layer by subtracting the mean and dividing by the standard deviation of each mini-batch.
After normalization, it adjusts the normalized activations using learned scaling and shifting parameters. These parameters enable the network to instantaneously scale and shift the activations thereby maintaining the network's ability to represent complex patterns in the data.
The parameters and are learned during training through backpropagation. This allows the network to adjust the normalization and ensure that the activations are in the appropriate range for learning.
It is typically applied after the convolutional and activation layers in a CNN before passing the outputs to the next layer. It can also be applied before or after the activation function, depending on the network architecture.
During training, Batch Normalization calculates the mean and variance of each mini-batch. During testing, it uses the averaged mean and variance that are calculated during training to normalize the activations. This ensures consistent normalization between training and testing.
For applying batch normalization layers after the convolutional layers and before the activation functions, we use tensorflow's'tf.keras.layers.BatchNormalization()'.
First Convolutional Block
Second Convolutional Block
Dense Layers(Classifier)
Flatten(): Converts 3D feature map to 1D.Dense(64): Learns high-level combinations.Dense(10, softmax): Outputs probabilities for 10 classes.In PyTorch, we can easily apply batch normalization in a CNN model. For applying BN in 1D Convolutional Neural Network model, we use 'nn.BatchNorm1d()'.
In this step, we structure our model:
Prediction step and input flow:
This code defines and creates a simple 1D Convolutional Neural Network (CNN1D) in PyTorch for classification tasks.
For applying Batch Normalization in 2D Convolutional Neural Network model, we use 'nn.BatchNorm2d()'.
In this step, we define the model:
Prediction step and input flow:
view(-1, 32*28*28): Flattens the 3D output to 1D for the dense layer.fc: Maps the extracted features to 10 output classes.This code defines a 2D Convolutional Neural Network (CNN) in PyTorch for image classification into 10 classes.
In conclusion, batch normalization stands as a technique used in enhancing the training and performance of convolutional neural networks (CNNs).
For more detailed explanation regarding the implementation, refer to