mindspore.ops.L2Loss
- class mindspore.ops.L2Loss[source]
Calculates half of the L2 norm, but do not square the result.
Set input as x and output as loss.
\[loss = \frac{\sum x ^ 2}{2}\]- Inputs:
input_x (Tensor) - Tensor for computing the L2 norm. Data type must be float16, float32 or float64.
- Outputs:
Tensor, has a Scalar Tensor with the same data type as input_x.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
- Examples
>>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float16) >>> l2_loss = L2Loss() >>> output = l2_loss(input_x) >>> print(output) 7.0