当前位置:网站首页>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)
结果:
边栏推荐
猜你喜欢
随机推荐
统计偏科最严重的前100名学生
MySQL知识总结 (四) 事务
The NDK portal: C
Bert系列之 Transformer详解
[VCU] Detailed S19 file (S-record)
NER(命名体识别)之 FLAT模型
ConstraintLayout from entry to abandonment
PyTorch(14)---使用现有的模型及其修改
文本匹配任务
牛客刷题汇总(持续更新中)
LLVM系列第三章:函数Function
标签加id 和 加号 两个文本框 和一个var 赋值
Policy Evaluation收敛性、炼丹与数学家
Win10不能启动WampServer图标呈橘黄色的解决方法
数据的表示方法和转换(二进制、八进制、十进制、十六进制)
Using the cloud GPU + pycharm training model to realize automatic background run programs, save training results, the server automatically power off
“自主可控”的正确姿势
原码、补码、反码
想做好分布式架构?这个知识点一定要理解透彻
The Handler you really understand?









