【学习笔记】神经网络—线性层
创始人
2024-11-28 17:05:57
0

查看官方文档:PyTorchicon-default.png?t=N7T8https://pytorch.org/

找到Linear Layers,如下所示 

 线性层函数介绍:

CLASStorch.nn.Linear(in_featuresout_featuresbias=Truedevice=Nonedtype=None)[SOURCE]icon-default.png?t=N7T8https://pytorch.org/docs/stable/_modules/torch/nn/modules/linear.html#Linear

参数介绍:

Parameters

  • in_features (int) – size of each input sample

  • out_features (int) – size of each output sample

  • bias (bool) – If set to , the layer will not learn an additive bias. Default: FalseTru

 线性层又叫全连接层,其中每个神经元与上一层所有神经元相连,一个简单的线性层如下图所示:

in_features指的是上图中x1,x2...xd的个数,即d

out_features 指的是上图中g1,g2...gL的个数,即L

bias:偏置,上面加不加b,就由这个bias控制,True时,加b        ·

Variables

  • weight (torch.Tensor) :相当于上图中的

  • bias : 相当于上图中的b

下面以一个简单的网络结果VGG16模型为例 :

 我们想实现下面这个:

import torch import torchvision from torch import nn from torch.nn import Linear from torch.utils.data import DataLoader  dataset=torchvision.datasets.CIFAR10('datasets',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.linear1 = Linear(in_features=196608,out_features=10)         def forward(self,input):             output = self.linear1(input)             return output   tudui=Tudui() for data in dataloader:     imgs,targets=data     print(imgs.shape)   # torch.Size([64, 3, 32, 32])   imgs个数为157,最后imgs[157]个数为14张图片     # output=torch.reshape(imgs,([1,1,1,-1]))  #最后一个-1代表让其自己计算     output = torch.flatten(imgs)     print(output.shape)  #torch.    Size([1, 1, 1, 196608])     output= tudui(output)     print(output.shape)  #经过神经网络 torch.Size([1, 1, 1, 10])

如下图所示,pytorch提供的一些网络模型,像AlexNet,VGG,ResNet等

 语义分割:Semantic Segmentationicon-default.png?t=N7T8https://pytorch.org/vision/0.9/models.html#semantic-segmentation

目标检测、实例分割和人体结构检测(行为检测) 

  • Object Detection, Instance Segmentation and Person Keypoint Detectionicon-default.png?t=N7T8https://pytorch.org/vision/0.9/models.html#object-detection-instance-segmentation-and-person-keypoint-detection

 

相关内容

热门资讯

四分钟了解“杭州都莱第三方辅助... 四分钟了解“杭州都莱第三方辅助软件”科普开挂辅助插件-原来真的是有挂1、进入游戏-大厅左侧-新手福利...
第八分钟科普!aa poker... 第八分钟科普!aa poker辅助,开心十三张小程序bug(必胜透视开挂辅助神器)1、开心十三张小程...
两分钟了解“决战卡五星开挂方法... 两分钟了解“决战卡五星开挂方法”专业开挂辅助软件-一直是真的挂1、打开软件启动之后找到中间准星的标志...
第九分钟理解!we-poker... 第九分钟理解!we-poker是什软件,越乡游义乌辅助器安全(线上透视开挂辅助教程)1.越乡游义乌辅...
第九分钟了解“拱趴大菠萝辅助”... 第九分钟了解“拱趴大菠萝辅助”安装开挂辅助插件-真是有挂1、每一步都需要思考,不同水平的挑战会更加具...
第五分钟领会!pokemmo辅... 第五分钟领会!pokemmo辅助器脚本下载,椰岛常胜游戏辅助工具免费版(规律透视开挂辅助教程)椰岛常...
第七分钟了解“花花生活圈辅助”... 第七分钟了解“花花生活圈辅助”必备开挂辅助插件-一直是有挂1、花花生活圈辅助透视辅助简单,花花生活圈...
第3分钟指导!哈糖大菠萝可以开... 第3分钟指导!哈糖大菠萝可以开挂,新西部大厅辅助(透视透视开挂辅助神器)1、许多玩家不知道哈糖大菠萝...
5分钟了解“欢乐联盟辅助器”专... 5分钟了解“欢乐联盟辅助器”专业开挂辅助神器-果然存在有挂;欢乐联盟辅助器辅助器中分为三种模型:欢乐...
第9分钟体悟!大菠萝辅助器,微... 第9分钟体悟!大菠萝辅助器,微信小游戏万年修改器(辅助透视开挂辅助神器)该软件可以轻松地帮助玩家将微...