Implementation:Tensorflow Tfjs Exports Initializers
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Layers_API, Initializers |
| Last Updated | 2026-02-10 06:00 GMT |
Overview
This module provides the public API factory functions for creating weight initializer instances in TensorFlow.js Layers. Initializers define the strategy for setting initial random or deterministic values for layer weights. These functions are exposed under the tf.initializers namespace and cover all standard initialization schemes including zeros, ones, constant, random distributions, variance-scaling methods (Glorot/He/LeCun), and orthogonal initialization.
Code Reference
Source Location
tfjs-layers/src/exports_initializers.ts (GitHub)
Imports
import {Constant, ConstantArgs, GlorotNormal, GlorotUniform, HeNormal, HeUniform,
Identity, IdentityArgs, Initializer, LeCunNormal, LeCunUniform, Ones,
Orthogonal, OrthogonalArgs, RandomNormal, RandomNormalArgs, RandomUniform,
RandomUniformArgs, SeedOnlyInitializerArgs, TruncatedNormal,
TruncatedNormalArgs, VarianceScaling, VarianceScalingArgs, Zeros}
from './initializers';
Factory Functions
| Function | Args Type | Description |
|---|---|---|
zeros() |
(none) | All weights initialized to 0 |
ones() |
(none) | All weights initialized to 1 |
constant(args) |
ConstantArgs |
Weights initialized to a given constant value |
randomUniform(args) |
RandomUniformArgs |
Uniform distribution between minval and maxval |
randomNormal(args) |
RandomNormalArgs |
Normal distribution with given mean and stddev |
truncatedNormal(args) |
TruncatedNormalArgs |
Truncated normal (values beyond 2 stddev re-drawn) |
identity(args) |
IdentityArgs |
Identity matrix (square 2D only) |
varianceScaling(config) |
VarianceScalingArgs |
Scale-adaptive initialization (configurable fan mode and distribution) |
glorotUniform(args) |
SeedOnlyInitializerArgs |
Xavier uniform: limit = sqrt(6 / (fan_in + fan_out)) |
glorotNormal(args) |
SeedOnlyInitializerArgs |
Xavier normal: stddev = sqrt(2 / (fan_in + fan_out)) |
heNormal(args) |
SeedOnlyInitializerArgs |
He normal: stddev = sqrt(2 / fan_in) |
heUniform(args) |
SeedOnlyInitializerArgs |
He uniform: limit = sqrt(6 / fan_in) |
leCunNormal(args) |
SeedOnlyInitializerArgs |
LeCun normal: stddev = sqrt(1 / fan_in) |
leCunUniform(args) |
SeedOnlyInitializerArgs |
LeCun uniform: limit = sqrt(3 / fan_in) |
orthogonal(args) |
OrthogonalArgs |
Random orthogonal matrix |
All functions return an Initializer instance.
I/O Contract
| Input | Output |
|---|---|
| Initializer-specific config args | Initializer instance that generates weight tensors of a requested shape
|
Usage Example
import * as tf from '@tensorflow/tfjs';
const model = tf.sequential();
model.add(tf.layers.dense({
units: 128,
kernelInitializer: tf.initializers.glorotNormal({seed: 42}),
biasInitializer: tf.initializers.zeros(),
inputShape: [256]
}));
Related Pages
- Tensorflow_Tfjs_Exports_Constraints - Factory functions for weight constraints
- Tensorflow_Tfjs_Exports_Regularizers - Factory functions for weight regularizers
- Tensorflow_Tfjs_Constraints - Constraint class implementations