mindspore/docs/api/api_python/ops/mindspore.ops.L2Loss.rst

37 lines
908 B
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.ops.L2Loss
====================
.. py:class:: mindspore.ops.L2Loss(*args, **kwargs)
计算Tensor的L2范数的一半不对结果进行 `sqrt` 开方。
`input_x` 设为x输出设为loss。
.. math::
loss = sum(x ** 2) / 2
**输入:**
**input_x** (Tensor) - 用于计算L2范数的Tensor。数据类型必须为float16或float32。
**输出:**
Tensor具有与 `input_x` 相同的数据类型。输出Tensor是loss的值是一个scalar Tensor。
**异常:**
- **TypeError** - `input_x` 不是Tensor。
- **TypeError** - `input_x` 的数据类型既不是float16也不是float32。
**支持平台:**
``Ascend`` ``GPU`` ``CPU``
**样例:**
>>> input_x = Tensor(np.array([1, 2, 3]), mindspore.float16)
>>> l2_loss = ops.L2Loss()
>>> output = l2_loss(input_x)
>>> print(output)
7.0