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.nn.L1Loss.rst 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. mindspore.nn.L1Loss
  2. =============================
  3. .. py:class:: mindspore.nn.L1Loss(reduction='mean')
  4. L1Loss用于计算预测值和目标值之间的平均绝对误差。
  5. 假设 :math:`x` 和 :math:`y` 为一维Tensor,长度 :math:`N` ,则计算 :math:`x` 和 :math:`y` 的loss而不进行降维操作(即reduction参数设置为"none")的公式如下:
  6. .. math::
  7. \ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad \text{with } l_n = \left| x_n - y_n \right|,
  8. 其中, :math:`N` 为batch size。如果 `reduction` 不是"none",则:
  9. .. math::
  10. \ell(x, y) =
  11. \begin{cases}
  12. \operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
  13. \operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
  14. \end{cases}
  15. **参数:**
  16. **reduction** (str) - 应用于loss的reduction类型。取值为"mean","sum",或"none"。默认值:"mean"。如果 `reduction` 为'mean'或'sum',则输出一个标量Tensor;如果 `reduction` 为'none',则输出Tensor的shape为广播后的shape。
  17. **输入:**
  18. - **logits** (Tensor) - 预测值,任意维度的Tensor。
  19. - **labels** (Tensor) - 目标值,通常情况下与 `logits` 的shape相同。但是如果 `logits` 和 `labels` 的shape不同,需要保证他们之间可以互相广播。
  20. **输出:**
  21. Tensor,类型为float。
  22. **异常:**
  23. - **ValueError** - `reduction` 不为"mean"、"sum"或"none"。
  24. - **ValueError** - `logits` 和 `labels` 有不同的shape,且不能互相广播。