import torch.NNA snnnn.MSE loss (reduction=' none ' )一、torch.nn.MSELoss )介绍
torch.nn.MSELoss ()是均方误差损失函数。 其公式为Ln=(xnyn ) 2L_n={ ) WMD DG } ^ 2ln=(xnyn ) 2
此处,x n x_n xn表示预测值张量,y n y_n yn表示真值张量。
二. torch.nn.MSELoss ()应用
代码:
importtorchimporttorch.nnasnnloss=nn.MSE loss (reduction=' none ' ) input=torch.tensor ([-0.1514,0.0744,- 0744 ] requires _ grad=true ] target=torch.tensor [ [0.1 .0.],[0.1 .1.] target (打印(输入)预测值张量
tensor ([-0.1514,0.0744,-1.5716],[-0.3198,-1.2424,-1.4921],[ 0.5548,0.8131,1.0369 ],requires [0