MCPcopy
hub / github.com/tensorflow/tfjs / l2Normalize

Function l2Normalize

tfjs-layers/src/losses.ts:25–35  ·  view source on GitHub ↗
(x: Tensor, axis?: number)

Source from the content-addressed store, hash-verified

23 * @param axis Axis along which to perform normalization.
24 */
25export function l2Normalize(x: Tensor, axis?: number): Tensor {
26 return tidy(() => {
27 if (x.dtype !== 'float32') {
28 x = tfc.cast(x, 'float32');
29 }
30 const squareSum = tfc.sum(K.square(x), axis, true);
31 const epsilonTensor = tfc.fill(squareSum.shape, epsilon());
32 const norm = tfc.sqrt(tfc.maximum(squareSum, epsilonTensor));
33 return tfc.div(x, norm);
34 });
35}
36
37export function meanSquaredError(yTrue: Tensor, yPred: Tensor): Tensor {
38 return tidy(() => tfc.mean(K.square(tfc.sub(yPred, yTrue)), -1));

Callers 2

mergeFunctionMethod · 0.90
cosineProximityFunction · 0.85

Calls 8

tidyFunction · 0.90
epsilonFunction · 0.90
sumMethod · 0.80
squareMethod · 0.80
sqrtMethod · 0.80
maximumMethod · 0.80
divMethod · 0.80
castMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…