zoukankan      html  css  js  c++  java
  • Pytorch MSELoss

    CLASS torch.nn.MSELoss(size_average=Nonereduce=Nonereduction='mean')

    Creates a criterion that measures the mean squared error (squared L2 norm) between each element in the input x and target yy.

    创建一个准则测量输入x和目标y每个元的平方二范数。

    x和y可以是任意形状的张量,每个张量总的元素个数为n。

    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'

    size_average和reduce正在被弃用,因此我们只看reduction参数

    reduction='none'

    The unreduced (i.e. with reduction set to 'none') loss can be described as:

    返回每个元素的平方二范数,shape与输入相同。

    reduction='sum'和reduction='mean'

    所有对应元素的平方二范数求和或求平均(sum / n)。

     1 a = torch.tensor([[[1., 2.]], [[1, 2]]])  # [2, 1, 2]
     2 b = torch.tensor([[[2., 4.]], [[2, 4.]]]) # [2, 1, 2]
     3 
     4 C =  torch.nn.MSELoss(reduction='none')
     5 
     6 loss = C(a, b)
     7 
     8 print(a)
     9 print(b)
    10 print(loss)
    11 
    12 >>>
    13 
    14 tensor([[[1., 2.]],
    15         [[1., 2.]]])
    16 
    17 tensor([[[2., 4.]],
    18         [[2., 4.]]])
    19 
    20 tensor([[[1., 4.]],
    21         [[1., 4.]]])  # 分别计算对应元素的平方二范数
    22 
    23 C =  torch.nn.MSELoss(reduction='sum')
    24 
    25 loss = C(a, b)
    26 print(loss)
    27 
    28 >>> tensor(10.) # 所有元素平方二范数之和
    29 
    30 C =  torch.nn.MSELoss(reduction='mean')
    31 
    32 loss = C(a, b)
    33 print(loss)
    34 >>> tensor(2.5000) # 所有元素平方二范数的均值

  • 相关阅读:
    片段
    告诉长夜
    明天
    开源一个WEB版本GEF,基于SVG的网页流程图框架
    RCP:ISourceLocator翻译
    SVG:textPath深入理解
    SVG:linearGradient渐变在直线上失效的问题解决方案
    【半平面交】BZOJ2618[Cqoi2006]凸多边形
    【旋转卡壳+凸包】BZOJ1185:[HNOI2007]最小矩形覆盖
    【凸包+旋转卡壳】平面最远点对
  • 原文地址:https://www.cnblogs.com/jiangkejie/p/13060365.html
Copyright © 2011-2022 走看看