当前位置:网站首页>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)
结果:
边栏推荐
猜你喜欢
随机推荐
文本匹配任务
liunx下mysql遇到的简单问题
2.RecyclerView基本使用
Win10不能启动WampServer图标呈橘黄色的解决方法
Seq2Seq模型PyTorch版本
关于UDF
St. Regis Takeaway Notes - Lecture 05 Getting Started with Redis
原码、补码、反码
LLVM系列第五章:全局变量Global Variable
MySQL知识总结 (三) 索引
内存申请(malloc)和释放(free)之上篇
Flink前期代码结构
Kubernetes架构和组件
MySQL知识总结 (二) 存储引擎
关于Flink
RN开发时遇到的问题
无人驾驶综述:等级划分
什么?都0202年了,你还不会屏幕适配?
boost库智能指针
Ehcache基础学习









