评价此页

torch.nn.functional.multi_margin_loss#

torch.nn.functional.multi_margin_loss(input, target, p=1, margin=1.0, weight=None, size_average=None, reduce=None, reduction='mean')[source]#

计算多类边距损失,支持可选的权重。

有关详细信息,请参阅 MultiMarginLoss

参数
  • input (Tensor) – 预测值。

  • target (Tensor) – 真值。

  • p (int, optional) – 默认为 1。仅支持 1 和 2。

  • margin (float, optional) – 多类边距损失的边距。默认为 1。

  • weight (Tensor, 可选) – 每个样本的权重。默认值:None。

  • size_average (bool, optional) – 已弃用(参见 reduction)。

  • reduce (bool, optional) – 已弃用(参见 reduction)。

  • reduction (str, optional) – 指定应用于输出的归约方式:‘none’ | ‘mean’ | ‘sum’。‘mean’:取输出的平均值。‘sum’:对输出求和。‘none’:不应用归约。默认值:‘mean’。

返回

多类边距损失(可选加权)。

返回类型

张量