Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Module

keras.initializers

keras.initializers provides built-in and custom strategies for creating initial layer-weight tensors. Use initializer objects or supported string names through layer-specific arguments such as kernel_initializer and bias_initializer.

How it works

The module provides callable strategies that create tensors for layer weights. Built-in classes cover common distributions, scaling rules, constant values, zeros, ones, identity matrices, and orthogonal matrices; layers receive them through initializer arguments or accepted string aliases.

Syntax

keras.initializers.Initializer()
keras.initializers.RandomNormal(mean=0.0, stddev=0.05, seed=None)
keras.initializers.RandomUniform(minval=-0.05, maxval=0.05, seed=None)
keras.initializers.TruncatedNormal(mean=0.0, stddev=0.05, seed=None)
keras.initializers.Zeros()
keras.initializers.Ones()
keras.initializers.Constant(value=0.0)
keras.initializers.Identity(gain=1.0)
keras.initializers.Orthogonal(gain=1.0, seed=None)

def __call__(self, shape, dtype=None):

Key points

  • Initializers determine how a layer's weights are created before training.
  • The exact initializer argument names are layer-specific.
  • Dense-style layers commonly expose separate kernel and bias initializer arguments.
  • The module includes a catalog of ready-made initializer classes.
  • A standard custom initializer should implement __call__(self, shape, dtype=None).
  • Custom initializer implementations can inherit from the module's base Initializer class.

Common mistakes

  • Constant accepts only a scalar value, and that value must be convertible to the requested dtype.
  • Identity is restricted to creating two-dimensional matrices.
  • For configurable custom initializers, define an Initializer subclass rather than relying on an unconfigured callable.

Example: Using initializers in a layer

import keras
from keras import layers

model = keras.Sequential([
    layers.Dense(
        64,
        kernel_initializer=keras.initializers.HeUniform(seed=42),
        bias_initializer=keras.initializers.Zeros(),
        input_shape=(32,),
    ),
    layers.Dense(10, activation="softmax"),
])

This runnable example gives the first Dense layer explicit kernel and bias initialization strategies.

When to use it

Initialize trainable kernels

Choosing a standard starting distribution for dense or convolutional weights.

Initialize biases

Setting bias variables to a predictable baseline.

Seed random initialization

Controlling repeatability when constructing models.

Build a custom initializer

Implementing project-specific weight creation logic.

Interview questions

QWhat is the callable contract for an initializer?

An initializer is a callable used to produce the initial tensor for a layer variable. Its usual call contract accepts shape and optional dtype, then returns a tensor with that shape and dtype.

Follow-up: How would you make a configurable custom initializer? Implement keras.initializers.Initializer, accept configuration in the constructor, and implement __call__(shape, dtype=None).

QHow are initializers supplied to layers?

Initializers can be passed to layer arguments such as kernel_initializer and bias_initializer. Keras also supports string names for built-in initializers, such as "random_normal" or "zeros".

Follow-up: Why might an object be preferable to a string? It lets you set initializer-specific arguments, such as a distribution's standard deviation or a random seed.

QWhat kinds of built-in initializers does Keras provide?

The module includes distribution-based initializers, scaling-based initializers, constant-valued initializers, and matrix-structure initializers. Examples include RandomNormal, VarianceScaling, Zeros, Identity, and Orthogonal.

Follow-up: Which initializer families are unsuitable for every shape? Identity requires a two-dimensional matrix, while other choices may impose their own shape or parameter constraints.

  • keras.initializers.Initializer
  • keras.initializers.RandomNormal
  • keras.initializers.RandomUniform
  • keras.initializers.TruncatedNormal
  • keras.initializers.VarianceScaling
  • keras.initializers.GlorotNormal
  • keras.initializers.GlorotUniform
  • keras.initializers.HeNormal

Source: Layer weight initializers - Keras. Checked 2026-10-15.