2.5K Star 8.4K Fork 4.7K

GVPMindSpore/mindspore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mindspore.nn.LossBase.rst 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-08-01 10:22 . fix docs issues

mindspore.nn.LossBase

.. py:class:: mindspore.nn.LossBase(reduction='mean')

    损失函数的基类。

    自定义损失函数时应重写 `construct` ,并使用方法 `self.get_loss` 将 `reduction` 应用于loss计算。

    参数:
        - **reduction** (str,可选) - 指定应用于输出结果的规约计算方式,可选 ``'none'`` 、 ``'mean'`` 、 ``'sum'`` ,默认值: ``'mean'`` 。

          - ``"none"``:不应用规约方法。
          - ``"mean"``:计算输出元素的(加权)平均值。
          - ``"sum"``:计算输出元素的总和。

    异常:
        - **ValueError** - `reduction` 不为 ``'none'`` 、 ``'mean'`` 或 ``'sum'`` 。

    .. py:method:: get_axis(x)

        获取输入的轴范围。

        参数:
            - **x** (Tensor) - 任何shape的Tensor。

    .. py:method:: get_loss(x, weights=1.0)

        计算加权损失。

        参数:
            - **x** (Tensor) - shape为 :math:`(N, *)` 的输入Tensor,其中 :math:`*` 表示任意数量的附加维度。
            - **weights** (Union[float, Tensor]) - 可选值,要么rank为0,要么rank与输入相同,并且必须可广播到输入(即,所有维度必须为 `1` ,或与相应输入的维度相同)。默认值: ``1.0``。

        返回:
            返回加权损失。
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore
r2.3.q1

搜索帮助