You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.ops.L2Normalize.rst 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. mindspore.ops.L2Normalize
  2. ==========================
  3. .. py:class:: mindspore.ops.L2Normalize(*args, **kwargs)
  4. L2范数归一化算子。
  5. 该算子将对输入 `x` 在给定 `axis` 上的元素进行归一化。函数定义如下:
  6. .. math::
  7. \displaylines{{\text{output} = \frac{x}{\sqrt{\text{max}(\parallel x_i \parallel^2 , \epsilon)} } } \\
  8. {\parallel x_i \parallel^2 = (\sum_{i}^{}\left | x_i \right | ^2 )^{1/2}} }
  9. 其中 :math:`\epsilon` 表示 `epsilon` , :math:`\sum_{i}^{}\left | x_i \right | ^2` 表示计算输入 `x` 在给定 `axis` 上元素的平方和。
  10. **参数:**
  11. - **axis** (Union[list(int), tuple(int), int]):输入的起始 `axis`,用于L2范数归一化。默认值:0。
  12. - **epsilon** (float):为了数值稳定性而引入的很小的浮点数。默认值:1e-4。
  13. **输入:**
  14. **x** (Tensor) - 计算归一化的输入。shape为 :math:`(N, *)` ,其中 :math:`*` 表示任意的附加维度数。数据类型必须为float16或float32。
  15. **输出:**
  16. Tensor,shape和数据类型与 `x` 的相同。
  17. **异常:**
  18. - **TypeError** - `axis` 不是list、tuple或int。
  19. - **TypeError** - `epsilon` 不是float。
  20. - **TypeError** - `x` 不是Tensor。
  21. - **TypeError** - `x` 的数据类型既不是float16也不是float32。
  22. **支持平台:**
  23. ``Ascend`` ``GPU`` ``CPU``
  24. **样例:**
  25. >>> l2_normalize = ops.L2Normalize()
  26. >>> x = Tensor(np.random.randint(-256, 256, (2, 3, 4)), mindspore.float32)
  27. >>> output = l2_normalize(x)
  28. >>> print(output.shape)
  29. (2, 3, 4)