大家好,又见面了,我是你们的朋友全栈君。
MSELOSS
代码语言:javascript复制CLASS torch.nn.MSELoss(size_average=None, reduce=None, reduction: str = 'mean')创建一个标准来测量输入x和目标y中每个元素之间的均方误差(L2范数平方)。
未减少的损失(即 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 fieldsize_averageis set toFalse, the losses are instead summed for each minibatch. Ignored when reduce isFalse. 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 onsize_average. WhenreduceisFalse, returns a loss per batch element instead and ignoressize_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_averageandreduceare in the process of being deprecated, and in the meantime, specifying either of those two args will overridereduction. 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
Examples:
代码语言:javascript复制>>> loss = nn.MSELoss()
>>> input = torch.randn(3, 5, requires_grad=True)
>>> target = torch.randn(3, 5)
>>> output = loss(input, target)
>>> output.backward()版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/192108.html原文链接:https://javaforall.cn


