mindspore.ops.margin_ranking_loss

mindspore.ops.margin_ranking_loss(input1, input2, target, margin=0.0, reduction='mean')[源代码]

排序损失函数,用于创建一个衡量给定损失的标准。

详情请参考 mindspore.nn.MarginRankingLoss

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore as ms
>>> from mindspore import Tensor, ops
>>> import numpy as np
>>> input1 = Tensor(np.array([0.3864, -2.4093, -1.4076]), ms.float32)
>>> input2 = Tensor(np.array([-0.6012, -1.6681, 1.2928]), ms.float32)
>>> target = sign(Tensor(np.array([-2, -2, 3]), ms.float32))
>>> output = ops.margin_ranking_loss(input1, input2, target)
>>> print(output)
1.2293333