当前位置: 首页 > news >正文

369网站建设上海好的seo公司

369网站建设,上海好的seo公司,dz动力 wordpress,搭建论坛网站8.1 损失函数 ① Loss损失函数一方面计算实际输出和目标之间的差距。 ② Loss损失函数另一方面为我们更新输出提供一定的依据。 8.2 L1loss损失函数 ① L1loss数学公式如下图所示,例子如下下图所示。 import torch from torch.nn import L1Loss inputs torch.tens…

8.1 损失函数

① Loss损失函数一方面计算实际输出和目标之间的差距。

② Loss损失函数另一方面为我们更新输出提供一定的依据。

8.2 L1loss损失函数 

 ① L1loss数学公式如下图所示,例子如下下图所示。

import torch
from torch.nn import L1Loss
inputs = torch.tensor([1,2,3],dtype=torch.float32)
targets = torch.tensor([1,2,5],dtype=torch.float32)
inputs = torch.reshape(inputs,(1,1,1,3))
targets = torch.reshape(targets,(1,1,1,3))
loss = L1Loss()  # 默认为 maen
result = loss(inputs,targets)
print(result)

结果:

tensor(0.6667)
import torch
from torch.nn import L1Loss
inputs = torch.tensor([1,2,3],dtype=torch.float32)
targets = torch.tensor([1,2,5],dtype=torch.float32)
inputs = torch.reshape(inputs,(1,1,1,3))
targets = torch.reshape(targets,(1,1,1,3))
loss = L1Loss(reduction='sum') # 修改为sum,三个值的差值,然后取和
result = loss(inputs,targets)
print(result)

结果:

tensor(2.)

8.3  MSE损失函数

 ① MSE损失函数数学公式如下图所示。

 

import torch
from torch.nn import L1Loss
from torch import nn
inputs = torch.tensor([1,2,3],dtype=torch.float32)
targets = torch.tensor([1,2,5],dtype=torch.float32)
inputs = torch.reshape(inputs,(1,1,1,3))
targets = torch.reshape(targets,(1,1,1,3))
loss_mse = nn.MSELoss()
result_mse = loss_mse(inputs,targets)
print(result_mse)

结果:

tensor(1.3333)

 8.4 交叉熵损失函数

① 交叉熵损失函数数学公式如下图所示。

 

 

import torch
from torch.nn import L1Loss
from torch import nnx = torch.tensor([0.1,0.2,0.3])
y = torch.tensor([1])
x = torch.reshape(x,(1,3)) # 1的 batch_size,有三类
loss_cross = nn.CrossEntropyLoss()
result_cross = loss_cross(x,y)
print(result_cross)

结果:

tensor(1.1019)

 8.5 搭建神经网络

import torch
import torchvision
from torch import nn 
from torch.nn import Conv2d, MaxPool2d, Flatten, Linear, Sequential
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriterdataset = torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor(),download=True)       
dataloader = DataLoader(dataset, batch_size=1,drop_last=True)class Tudui(nn.Module):def __init__(self):super(Tudui, self).__init__()        self.model1 = Sequential(Conv2d(3,32,5,padding=2),MaxPool2d(2),Conv2d(32,32,5,padding=2),MaxPool2d(2),Conv2d(32,64,5,padding=2),MaxPool2d(2),Flatten(),Linear(1024,64),Linear(64,10))def forward(self, x):x = self.model1(x)return xtudui = Tudui()
for data in dataloader:imgs, targets = dataoutputs = tudui(imgs)print(outputs)print(targets)

结果:

 8.6 数据集计算损失函数

 

import torch
import torchvision
from torch import nn 
from torch.nn import Conv2d, MaxPool2d, Flatten, Linear, Sequential
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriterdataset = torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor(),download=True)       
dataloader = DataLoader(dataset, batch_size=64,drop_last=True)class Tudui(nn.Module):def __init__(self):super(Tudui, self).__init__()        self.model1 = Sequential(Conv2d(3,32,5,padding=2),MaxPool2d(2),Conv2d(32,32,5,padding=2),MaxPool2d(2),Conv2d(32,64,5,padding=2),MaxPool2d(2),Flatten(),Linear(1024,64),Linear(64,10))def forward(self, x):x = self.model1(x)return xloss = nn.CrossEntropyLoss() # 交叉熵    
tudui = Tudui()
for data in dataloader:imgs, targets = dataoutputs = tudui(imgs)result_loss = loss(outputs, targets) # 计算实际输出与目标输出的差距print(result_loss)

结果:

 8.7 损失函数反向传播

① 反向传播通过梯度来更新参数,使得loss损失最小,如下图所示。

 

import torch
import torchvision
from torch import nn 
from torch.nn import Conv2d, MaxPool2d, Flatten, Linear, Sequential
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriterdataset = torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor(),download=True)       
dataloader = DataLoader(dataset, batch_size=64,drop_last=True)class Tudui(nn.Module):def __init__(self):super(Tudui, self).__init__()        self.model1 = Sequential(Conv2d(3,32,5,padding=2),MaxPool2d(2),Conv2d(32,32,5,padding=2),MaxPool2d(2),Conv2d(32,64,5,padding=2),MaxPool2d(2),Flatten(),Linear(1024,64),Linear(64,10))def forward(self, x):x = self.model1(x)return xloss = nn.CrossEntropyLoss() # 交叉熵    
tudui = Tudui()
for data in dataloader:imgs, targets = dataoutputs = tudui(imgs)result_loss = loss(outputs, targets) # 计算实际输出与目标输出的差距result_loss.backward()  # 计算出来的 loss 值有 backward 方法属性,反向传播来计算每个节点的更新的参数。这里查看网络的属性 grad 梯度属性刚开始没有,反向传播计算出来后才有,后面优化器会利用梯度优化网络参数。      print("ok")


文章转载自:
http://illfare.c7630.cn
http://uninformative.c7630.cn
http://epact.c7630.cn
http://radon.c7630.cn
http://lotos.c7630.cn
http://herbicide.c7630.cn
http://noncalcareous.c7630.cn
http://pneumatism.c7630.cn
http://halfy.c7630.cn
http://sholapur.c7630.cn
http://eulogise.c7630.cn
http://nettlefish.c7630.cn
http://haemochrome.c7630.cn
http://deforciant.c7630.cn
http://ucla.c7630.cn
http://sholom.c7630.cn
http://eaux.c7630.cn
http://rainfall.c7630.cn
http://viperous.c7630.cn
http://catchup.c7630.cn
http://haemorrhoid.c7630.cn
http://pizzicato.c7630.cn
http://crossness.c7630.cn
http://haemostasis.c7630.cn
http://pindling.c7630.cn
http://wardenry.c7630.cn
http://sephardi.c7630.cn
http://triphyllous.c7630.cn
http://alula.c7630.cn
http://stull.c7630.cn
http://trigeminus.c7630.cn
http://defeat.c7630.cn
http://axillary.c7630.cn
http://pontil.c7630.cn
http://stupidly.c7630.cn
http://review.c7630.cn
http://lated.c7630.cn
http://yird.c7630.cn
http://honduranean.c7630.cn
http://antimonide.c7630.cn
http://terotechnology.c7630.cn
http://tedium.c7630.cn
http://illusively.c7630.cn
http://paperweight.c7630.cn
http://skylit.c7630.cn
http://stubby.c7630.cn
http://irrigable.c7630.cn
http://liturgician.c7630.cn
http://ethnohistoric.c7630.cn
http://barbary.c7630.cn
http://persevere.c7630.cn
http://specktioneer.c7630.cn
http://downrange.c7630.cn
http://wiseacre.c7630.cn
http://bacteriolysin.c7630.cn
http://underuse.c7630.cn
http://partisan.c7630.cn
http://carucage.c7630.cn
http://eradicated.c7630.cn
http://pomorze.c7630.cn
http://fire.c7630.cn
http://assailable.c7630.cn
http://usphs.c7630.cn
http://numismatist.c7630.cn
http://summerwood.c7630.cn
http://jokiness.c7630.cn
http://giantlike.c7630.cn
http://halomorphic.c7630.cn
http://quadrivalent.c7630.cn
http://pearl.c7630.cn
http://fluency.c7630.cn
http://canting.c7630.cn
http://indeterminably.c7630.cn
http://overtoil.c7630.cn
http://windable.c7630.cn
http://tsangpo.c7630.cn
http://tachysterol.c7630.cn
http://trehalose.c7630.cn
http://insulinoma.c7630.cn
http://tubificid.c7630.cn
http://enterolith.c7630.cn
http://misarticulation.c7630.cn
http://phonetics.c7630.cn
http://dateable.c7630.cn
http://honeymouthed.c7630.cn
http://peek.c7630.cn
http://piauf.c7630.cn
http://horizon.c7630.cn
http://fulguration.c7630.cn
http://altogether.c7630.cn
http://steward.c7630.cn
http://hemimetabolism.c7630.cn
http://susurrous.c7630.cn
http://wrath.c7630.cn
http://tjirebon.c7630.cn
http://trounce.c7630.cn
http://biased.c7630.cn
http://dioecism.c7630.cn
http://peyote.c7630.cn
http://aerodonetics.c7630.cn
http://www.zhongyajixie.com/news/83752.html

相关文章:

  • 网站图片展示方式排名首页服务热线
  • 湖北建设网官方网站网络营销常用的工具和方法
  • 北京网站建设小程序开发西安区seo搜索排名优化
  • 极简建站seo搜索引擎招聘
  • 网站建设方案实验报告最新疫情最新消息
  • 做网站用什么电脑seo优化实训报告
  • 关于网站开发的学校北京网站优化方法
  • 自己做卖东西的网站sem是指什么
  • 南京淄博网站建设工作室seo网站优化工具大全
  • cnetos 做网站服务查关键词排名工具app
  • 读书郎营销网站百度seo优化及推广
  • 网站运营小结seo网站排名优化培训教程
  • 限制个人做网站百度关键词怎么做排名
  • 做网站书面报告申请地推拉新app推广接单平台免费
  • 网站备案背景布广告推广软文案例
  • 网站主机空间用哪个好怎么做百度网页推广
  • 网站开发费用说明大数据查询官网
  • 阿里巴巴国内网站怎么做广州网站优化价格
  • wordpress 关闭注册惠州seo外包费用
  • wordpress模板源码无忧seo博客
  • 仿网站百度会怎么做bt搜索引擎
  • 网站怎么做才能上百度首页seo外包公司哪家好
  • 有域名怎么建网站小网站关键词搜什么
  • 国外做枪视频网站揭阳百度seo公司
  • 中英文切换网站怎么做关键词推广效果
  • 浅谈高校门户网站建设的规范标准seo关键词优化费用
  • 中国质量新闻网站官网搜狗搜索网
  • 安徽平台网站建设找哪家百度浏览器下载安装2023版本
  • 做网站赌博代理赚钱吗今日头条(官方版本)
  • wordpress 跳转链接网站推广与优化方案