当前位置:网站首页>PyTorch⑨---卷积神经网络_线性层
PyTorch⑨---卷积神经网络_线性层
2022-08-02 14:07:00 【伏月三十】
线性层
在卷积神经网络里最后几层,会把卷积层摊开平放到全连接层里计算,然后进入sofmax进行分类。线性层相当于全连接层。
例如在vgg16里:
77512----torch.flatten(imgs)—>114096—Linear(4096,1000)—>111000
import torch.nn
import torchvision
from torch import nn
from torch.nn import Linear
from torch.utils.data import DataLoader
dataset=torchvision.datasets.CIFAR10("dataset_CIFAR10",
train=False,
transform=torchvision.transforms.ToTensor())
dataloader=DataLoader(dataset,batch_size=64,drop_last=True)
class Demo(nn.Module):
def __init__(self) -> None:
super().__init__()
self.linear1=Linear(196608,10) #把全部展开的196608变成10,最后分类的结果是10类
def forward(self,input):
output=self.linear1(input)
return output
demo=Demo()
for data in dataloader:
imgs,targets=data
print(imgs.shape)
output=torch.flatten(imgs)
print(output.shape)
output=demo(output)
print(output.shape)
结果:
边栏推荐
猜你喜欢
随机推荐
mysql常用函数
没学好统计学的下场
宝塔搭建PESCMS-Ticket开源客服工单系统源码实测
最小树高度
数据偏见的背后是什么
[VCU] Detailed S19 file (S-record)
一文带你快速掌握Kotlin核心技能
1.RecyclerView是什么
不可不知的反汇编相关知识
LLVM系列第三章:函数Function
redis入门-1-redis概念和基础
The Handler you really understand?
利用红外-可见光图像数据集OTCBVS打通图像融合、目标检测和目标跟踪
2. Basic use RecyclerView
LLVM系列第八章:算术运算语句Arithmetic Statement
华为防火墙
7.如何给RecyclerView添加Click和LongClick事件
执行npm install有错误error
ConstraintLayout from entry to abandonment
Kubernetes架构和组件









