推荐一下:深度学习AI-计算机视觉(CV)-整体解决方案课件(Yolo+Flask+Vue+Waitress+Nginx)
视频教程:https://www.bilibili.com/video/BV19h4y1874T/?spm_id_from=333.999.0.0
均方误差损失函数(MSE,mean squared error)
回归问题解决的是对具体数值的预测,比如房价预测、销量预测等等,解决回归问题的神经网络一般只有一个输出节点,这个节点的输出值就是预测值。本文主要介绍回归问题下的损失函数——均方误差(MSE,mean squared error)。
公式如下:
Pyorch实现的MSE
import torch
import numpy as np
loss_fn = torch.nn.MSELoss(reduce=False, size_average=False)
a=np.array([[1,2],[3,4]])
b=np.array([[2,3],[4,5]])
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(input.float())
print(target.float())
print(loss)
a=np.array([[1,2],[3,4]])
b=np.array([[2,3],[4,6]])
loss_fn = torch.nn.MSELoss(reduce=True, size_average=True)
input = torch.autograd.Variable(torch.from_numpy(a))
target = torch.autograd.Variable(torch.from_numpy(b))
loss = loss_fn(input.float(), target.float())
print(input.float())
print(target.float())
print(loss)