神经网络实战2-损失函数和反向传播


其实就是通过求偏导的方式,求出各个权重大小

loss函数是找最小值的,要求导,在计算机里面计算导数是倒着来的,所以叫反向传播。

c 复制代码
import  torch
from torch.nn import L1Loss

inputs=torch.tensor([1,2,3],dtype=torch.float32)
target=torch.tensor([1,2,5],dtype=torch.float32)

inputs=torch.reshape(inputs,(1,1,1,3))#这里rershape的目的是增加batch_size这一数据
target=torch.reshape(target,(1,1,1,3))
loss=L1Loss()
result=loss(inputs,target)
print(result)

对以上的一个简单设计

loss的默认reduction是mean即平均值

我们需要的是相加

c 复制代码
import  torch
from torch.nn import L1Loss

inputs=torch.tensor([1,2,3],dtype=torch.float32)
target=torch.tensor([1,2,5],dtype=torch.float32)

inputs=torch.reshape(inputs,(1,1,1,3))#这里rershape的目的是增加batch_size这一数据
target=torch.reshape(target,(1,1,1,3))
loss=L1Loss(reduction='sum')
result=loss(inputs,target)
print(result)

均方差

反向传播

相关推荐
牧子川2 小时前
009-Transformer-Architecture
人工智能·深度学习·transformer
dfsj660114 小时前
第四章:深度学习革命
人工智能·深度学习
cskywit4 小时前
【CVPR2024】用Diffusion“造”遥感分割数据:SatSynth论文解读
人工智能·深度学习·计算机视觉
薛定e的猫咪4 小时前
因果推理研究方向综述笔记
人工智能·笔记·深度学习·算法
老毛肚5 小时前
卷积神经网络CNN
人工智能·深度学习·cnn
八月瓜科技6 小时前
用AI来省电?iOS26.5正式版全球推送:信号弱网双提升,AI省电模式上新
数据库·人工智能·科技·深度学习·机器人
碧海银沙音频科技研究院6 小时前
音箱在加入 NN AEC(神经网络声学回声消除) 后出现反复重启问题解决
人工智能·深度学习·算法
现代野蛮人8 小时前
【深度学习】 —— VGG-16 网络实现猫狗识别
网络·人工智能·python·深度学习·tensorflow
一个小猴子`8 小时前
Pytorch快速复习
人工智能·pytorch·python
五月底_8 小时前
Transformer
人工智能·深度学习