MCPcopy Create free account
hub / github.com/tensorflow/tfjs / regularNormalizeBatchInTraining

Function regularNormalizeBatchInTraining

tfjs-layers/src/layers/normalization.ts:89–100  ·  view source on GitHub ↗

* Non-broadcasting batch normalization for use in training (not inference). * * The input is normalized to zero mean and unit variance along the * `reductionAxes`, followed by scaling with `gamma` and shifted by `beta`. * The result of that is returned as the first element * of the returned `Ar

(
    x: Tensor, gamma: Tensor, beta: Tensor, reductionAxes: number[],
    epsilon = 1e-3)

Source from the content-addressed store, hash-verified

87 * [normalized tensor, mean of input, variance of input].
88 */
89function regularNormalizeBatchInTraining(
90 x: Tensor, gamma: Tensor, beta: Tensor, reductionAxes: number[],
91 epsilon = 1e-3): [Tensor, Tensor, Tensor] {
92 return tidy(() => {
93 const meanAndVariance = tfc.moments(x, reductionAxes);
94 const mean = meanAndVariance.mean;
95 const variance = meanAndVariance.variance;
96 const normed =
97 batchNormalization(x, mean, variance, beta, gamma, epsilon);
98 return [normed, mean, variance];
99 }) as [Tensor, Tensor, Tensor];
100}
101
102/**
103 * Broadcasting batch normalization for use in training (not inference).

Callers 1

normalizeBatchInTrainingFunction · 0.85

Calls 2

tidyFunction · 0.90
batchNormalizationFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…