torch.nn.MSELoss()函数解读

    • 函数作用
      torch.nn.MSELoss() 求predict和target之间的loss。
    • 代码示例
      单个求其loss:
    • crit = nn.MSELoss()
      # target = torch.Tensor(1)
      # target[0] = 10
      # res = torch.Tensor(1)
      # res[0] = 5
      # cost  = crit(res,target)#25
      # print(cost)
      target = torch.Tensor(2)
      target[0] = 10
      target[1] = 6
      res = torch.Tensor(2)
      res[0] = 5
      res[1] = 3
      cost  = crit(res,target)#(25+9)/2
      print(cost)

       

posted on 2020-10-30 15:22  cltt  阅读(8018)  评论(0编辑  收藏  举报

导航