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)

       


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM