l2_normalize¶
dragon.vm.tensorflow.math.
l2_normalize
(
x,
axis=None,
epsilon=1e-12,
name=None
)[source]¶Apply the l2 normalization.
The L2-Normalization is defined as:
\[y = \frac{x}{\left\|x\right\|_{2} + \epsilon} \]The argument
axis
could be negative or None:x = tf.constant([[1, 2, 3], [4, 5, 6]], 'float32') # A negative ``axis`` is the last-k axis print(tf.math.l2_normalize(x, 1)) print(tf.math.l2_normalize(x, -1)) # Equivalent # If ``axis`` is None, the vector-style reduction # will be applied to compute a norm scalar print(tf.math.l2_normalize(x)) # Also, ``axis`` could be a sequence of integers print(tf.math.l2_normalize(x, [0, 1]))
- Parameters:
- x (dragon.Tensor) – The tensor \(x\).
- axis (Union[int, Sequence[int]], optional) – The axis to compute norm.
- epsilon (float, optional, default=1e-12) – The value to \(\epsilon\).
- name (str, optional) – The operation name.
- Returns:
dragon.Tensor – The output tensor.