* 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)
| 87 | * [normalized tensor, mean of input, variance of input]. |
| 88 | */ |
| 89 | function 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). |
no test coverage detected
searching dependent graphs…