mindspore.ops.L2Loss
- class mindspore.ops.L2Loss[source]
Calculates half of the L2 norm of a tensor without using the sqrt.
Set input_x as x and output as loss.
\[loss = sum(x ** 2) / 2\]- Inputs:
input_x (Tensor) - A input Tensor. Data type must be float16 or float32.
- Outputs:
Tensor, has the same dtype as input_x. The output tensor is the value of loss which is a scalar tensor.
- Raises
- Supported Platforms:
Ascend
GPU
CPU
- Examples
>>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float16) >>> l2_loss = ops.L2Loss() >>> output = l2_loss(input_x) >>> print(output) 7.0