deep learning
batch normalization
convolutional layers
neural networks
bias terms

Can not use both bias and batch normalization in convolution layers

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

In deep learning, Convolutional Neural Networks (CNNs) have emerged as a fundamental architecture for various tasks, such as image recognition and classification. Key components within these networks, such as bias terms and batch normalization, greatly influence the performance of a model. However, a common point of discussion is the compatibility and necessity of using both biases and batch normalization in convolution layers. This article explores the technical underpinnings of these components and explains why they are generally not used together.

Convolution Layers and Biases

Convolution layers apply filters to input data to extract features. They typically include a bias term, which allows the layer to fit the data better by shifting the activation function. Mathematically, the operation of a convolution layer can be expressed as:

Y=W\*X+bY = W \* X + b

where: • YY is the output feature map, • WW is the filter (or kernel), • XX is the input data, and • bb is the bias.

The addition of biases enables the network to learn an offset for each feature map independently, providing additional flexibility during learning.

Batch Normalization

Batch normalization (BatchNorm) is a technique that normalizes the inputs of each layer to reduce internal covariate shift. This normalization accelerates training, improves convergence, and can act as a regularizer. The process can be expressed as:

  1. Calculate the mean μB\mu_B and variance σB2\sigma_B^2 of the batch for each feature.
  2. Normalize each input xix_i as:
    x^_i=x_iμ_Bσ_B2+ϵ\hat{x}\_i = \frac{x\_i - \mu\_B}{\sqrt{\sigma\_B^2 + \epsilon}}
  3. Scale and shift the normalized value:
    y_i=γx^_i+βy\_i = \gamma \hat{x}\_i + \beta

Here, γ\gamma (gamma) and β\beta (beta) are learned parameters that restore the network's expressive power. The normalization also provides a bias-like term through β\beta.

Why Not Use Both Bias and BatchNorm?

When using batch normalization, the bias in the preceding layer becomes redundant. Here's why:

  1. Reduction of Effectiveness: Since batch normalization involves both centering the data and introducing a shift via β\beta, any bias added before batch normalization has no effect after the layer normalization.
  2. Computational Overhead: Including biases when they have no impact on the network’s output means unnecessary computations, thus increasing the model's complexity without adding value.
  3. Parameter Redundancy: Incorporating both adds to parameter redundancy, potentially leading to overfitting due to increased parameter count without contributing to greater learning capacity.

Practically, imposing a constraint that drops biases when batch normalization is employed provides efficiency in both computation and memory usage.

Best Practices

Configuration: When designing CNN architectures, if batch normalization is part of the network layers, omit biases from those layers. This simplification leads to efficient model training and less complexity. • Performance: Regular monitoring and validation on batch normalization layers ensure no performance degradation.

Case Study

Consider a simple CNN with the following layers:

  1. Convolution Layer 1 (with bias)
  2. Batch Normalization
  3. Activation Layer (ReLU)
  4. Convolution Layer 2 (without bias)
  5. Batch Normalization
  6. Activation Layer (ReLU)

In this structure, only the first convolution layer employs a bias term, whereas subsequent layers leave them out due to the presence of batch normalization. Testing this setup generally results in similar, if not better, performance while optimizing computational resources.

Key Points Summary

Below is a table that highlights the essential points.

AspectConvolutions with BiasConvolutions with BatchNorm
Parameter EffectOffsets the feature mapNormalizes and scales feature map
Influence on OutputDirect addition before activationNormalized output shift via β\beta
Computational ComplexityIncreased due to added parameterReduced by removing unnecessary bias
Use CaseSuitable when batch norm is not usedCommon practice with batch norm use

Conclusion

To summarize, while both biases and batch normalization are useful techniques in neural networks, they do not need to coexist in the presence of each other in layers. Batch normalization inherently compensates and optimizes for what biases provide, hence excluding biases when its applied is a practical approach. Understanding these nuances enables design choices that enhance the efficiency and performance of convolutional neural networks.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.