赞
踩
CLASS torch.nn.L1Loss(size_average=None, reduce=None, reduction: str = 'mean')
创建一个标准来测量输入x和目标y中每个元素之间的平均绝对误差(MAE)。
未减少的损失(即 reduction
设置为'none'
)可以描述为:
其中 N 是 batch size. 如果 reduction
不是 'none'
(默认为 'mean'
), 那么:
x和y是任意形状的张量,每个张量总共有n个元素。
平均值运算仍对所有元素进行运算,并除以n。
如果设置 reduction = 'sum'
,则可以避免除以n。
Parameters
size_average (bool, optional) – Deprecated (see reduction
). By default, the losses are averaged over each loss element in the batch. Note that for some losses, there are multiple elements per sample. If the field size_average
is set to False
, the losses are instead summed for each minibatch. Ignored when reduce is False
. Default: True。默认情况下,损失是
batch中每个损失元素的平均数。 请注意,对于某些损失,每个样本有多个元素。 如果将size_average字段设置为False,则损失是每个minibatch的总和。 当reduce为False时被忽略。 默认值:True。
reduce (bool, optional) – Deprecated (see reduction
). By default, the losses are averaged or summed over observations for each minibatch depending on size_average
. When reduce
is False
, returns a loss per batch element instead and ignores size_average
. Default: True。默认情况下,根据size_average对每个minibatch的观察结果求平均或求和。 当reduce为False时,返回每个batch元素损失,并忽略size_average。 默认值:True。
reduction (string, optional) – Specifies the reduction to apply to the output: 'none'
| 'mean'
| 'sum'
. 'none'
: no reduction will be applied, 'mean'
: the sum of the output will be divided by the number of elements in the output, 'sum'
: the output will be summed. Note: size_average
and reduce
are in the process of being deprecated, and in the meantime, specifying either of those two args will override reduction
. Default: 'mean'。指定要应用于输出的缩减量:'none'| “mean” | 'sum'。 'none':不应用任何reduction,'mean':输出的总和除以输出中元素的数量,'sum':输出的总和。 注意:size_average和reduce正在弃用过程中,与此同时,指定这两个args中的任何一个将覆盖reduction。 默认值:'mean'
Shape:
Input: (N, ∗) where ∗ means, any number of additional dimensions
Target: (N, ∗), same shape as the input
Output: scalar. If reduction
is 'none'
, then (N, ∗), same shape as the input
Examples:
- >>> loss = nn.L1Loss()
- >>> input = torch.randn(3, 5, requires_grad=True)
- >>> target = torch.randn(3, 5)
- >>> output = loss(input, target)
- >>> output.backward()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。