mindspore.nn.Loss
- class mindspore.nn.Loss[源代码]
计算loss的平均值。如果每 \(n\) 次迭代调用一次 update 方法,则计算结果为:
\[loss = \frac{\sum_{k=1}^{n}loss_k}{n}\]- 支持平台:
Ascend
GPU
CPU
样例:
>>> import numpy as np >>> import mindspore >>> from mindspore import nn, Tensor >>> >>> x = Tensor(np.array(0.2), mindspore.float32) >>> loss = nn.Loss() >>> loss.clear() >>> loss.update(x) >>> result = loss.eval() >>> print(result) 0.20000000298023224