Xavier and he_normal initialization difference
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
In the world of deep learning, choosing the right initialization method for neural network weights is crucial to ensure faster convergence and better performance. Two popular initialization strategies are Xavier (or Glorot) initialization and He (or He_normal) initialization. These methods have become standard practices in training deep neural networks, such as convolutional neural networks (CNNs) and fully connected networks. This article explores the differences between Xavier and He_normal initialization, providing technical explanations and examples.
Understanding Weight Initialization
Weight initialization is a technique for setting the initial weights of a neural network before the training begins. The choice of initialization can significantly impact the speed of convergence and the final performance of the network.
Why is Initialization Important?
• Avoid Vanishing/Exploding Gradients: Poor initialization can cause gradients to vanish (become too small) or explode (become too large), obstructing the learning process. • Symmetry Breaking: Proper initialization ensures that different neurons start by learning different things.
Xavier Initialization
Xavier initialization, named after its developer Xavier Glorot, is designed to maintain the variance of activations and backpropagated gradients across layers. It is particularly suited for networks using the sigmoid or hyperbolic tangent (tanh) activation functions.
Formula
For a layer with `n_{input}` incoming connections (or fan-in), the weights are initialized as follows:
• Uniform distribution:
• Normal distribution:
Use Case
Xavier initialization is generally used for symmetric activation functions such as sigmoid or tanh due to its derivation, which assumes symmetry.
He_normal Initialization
He_normal initialization, introduced by He et al., is optimized for activation functions like Rectified Linear Units (ReLU). It considers the rectifier's properties, allowing better flow of gradients throughout the neural network.
Formula
For a layer with `n_{input}` incoming connections, the weights are initialized as follows:
• Normal distribution:
Use Case
He_normal initialization is particularly effective for ReLU and its variants (e.g., Leaky ReLU, Parametric ReLU).
Comparison of Xavier and He_normal Initialization
| Feature | Xavier Initialization | He_normal Initialization |
| Activation Functions | Best with sigmoid or tanh | Best with ReLU, Leaky ReLU, etc. |
| Distribution | Uniform or Normal | Normal |
| Variance Consideration | Considers both incoming and outgoing layer sizes | Considers only the incoming layer size |
| Purpose | Balances symmetry assumptions for activations and outputs | Focuses on gradients' flow in ReLU networks |
| Formula - Uniform | N/A | |
| Formula - Normal |
Practical Example
Let's illustrate the impact of both initialization methods using a simple neural network trained on the MNIST dataset.
Setup
Assume a simple feedforward network with:
• Input layer: 784 units (28x28 pixels) • One hidden layer: 128 units • Output layer: 10 units (one for each class)
Code Snippet
Below is a Python snippet showing how to implement Xavier and He_normal initializations using TensorFlow:
• Xavier Glorot, Yoshua Bengio: "Understanding the difficulty of training deep feedforward neural networks" • Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun: "Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification"
Related reading
- Y label shape for time_distributed lstm
- YOLO object detection how does the algorithm predict bounding boxes larger than a grid cell?
- 4D input in LSTM layer in Keras
- About tensorflow Metadata and RunOptions
- About tensorflow.initialize_all_variables
- Accessing PyTorch GPU matrix from TensorFlow directly
- Accuracy issue in caffe
- Adam optimizer goes haywire after 200k batches, training loss grows
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.