当前位置:网站首页>动手学深度学习_NiN
动手学深度学习_NiN
2022-08-04 21:00:00 【CV小Rookie】

LeNet 、AlexNet 和 VGG 都有一个共同的设计模式:通过一系列的卷积层与汇聚层来提取空间结构特征;然后通过全连接层对特征的表征进行处理。 AlexNet 和 VGG 对 LeNet 的改进主要在于如何扩大和加深这两个模块。
然而,如果使用了全连接层,可能会完全放弃表征的空间结构。 网络中的网络(NiN)提供了一个非常简单的解决方案:在每个像素的通道上分别使用多层感知机(其实就是加两层 1 x 1 的卷积,因为前面说过,1 x 1 的卷积相当于参数共享的 MLP)

通过图解可以看到,NiN 网络就是由 nin_block 组成,一个 nin_block 由一个卷积层 + 两个
1 x 1卷积组成:

最后的输出取消使用 MLP ,而是使用一个全局的 Pooling 将特征图的高和宽变为1,最后使用 Flatten 展平,得到输出。
def nin_block(in_channels, out_channels, kernel_size, strides, padding):
return nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size, strides, padding),
nn.ReLU(),
nn.Conv2d(out_channels, out_channels, kernel_size=1), nn.ReLU(),
nn.Conv2d(out_channels, out_channels, kernel_size=1), nn.ReLU())
class NiN(nn.Module):
def __init__(self):
super(NiN, self).__init__()
self.model =nn.Sequential(
nin_block(1, 96, kernel_size=11, strides=4, padding=0),
nn.MaxPool2d(3, stride=2),
nin_block(96, 256, kernel_size=5, strides=1, padding=2),
nn.MaxPool2d(3, stride=2),
nin_block(256, 384, kernel_size=3, strides=1, padding=1),
nn.MaxPool2d(3, stride=2),
nn.Dropout(0.5),
# 标签类别数是10
nin_block(384, 10, kernel_size=3, strides=1, padding=1),
nn.AdaptiveAvgPool2d((1, 1)),
# 将四维的输出转成二维的输出,其形状为(批量大小,10)
nn.Flatten()
)
def forward(self,x):
x = self.model(x)
return x每一层的输出的 size :
Sequential output shape: torch.Size([1, 96, 54, 54]) MaxPool2d output shape: torch.Size([1, 96, 26, 26]) Sequential output shape: torch.Size([1, 256, 26, 26]) MaxPool2d output shape: torch.Size([1, 256, 12, 12]) Sequential output shape: torch.Size([1, 384, 12, 12]) MaxPool2d output shape: torch.Size([1, 384, 5, 5]) Dropout output shape: torch.Size([1, 384, 5, 5]) Sequential output shape: torch.Size([1, 10, 5, 5]) AdaptiveAvgPool2d output shape: torch.Size([1, 10, 1, 1]) Flatten output shape: torch.Size([1, 10])
边栏推荐
猜你喜欢

MATLAB中readtimetable函数用法

Retrofit的使用及原理详解

【2022牛客多校5 A题 Don‘t Starve】DP

3、IO流之字节流和字符流
![[Academic related] Tsinghua professor persuaded to quit his Ph.D.:I have seen too many doctoral students have mental breakdowns, mental imbalances, physical collapses, and nothing!...](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Academic related] Tsinghua professor persuaded to quit his Ph.D.:I have seen too many doctoral students have mental breakdowns, mental imbalances, physical collapses, and nothing!...

无代码平台字段设置:基础设置入门教程

构建Buildroot根文件系统(I.MX6ULL)

Tear down the underlying mechanism of the five JOINs of SparkSQL

经验分享|盘点企业进行知识管理时的困惑类型

Configure laravel queue method using fort app manager
随机推荐
Matlab画图2
【debug】postgres数据存储错乱
QT(42)-QT线程-线程调用槽函数
构建Buildroot根文件系统(I.MX6ULL)
After the tester with 10 years of service "naked resignation" from the big factory...
大资本已开始逃离加密领域?
Tear down the underlying mechanism of the five JOINs of SparkSQL
dotnet 启动 JIT 多核心编译提升启动性能
Data warehouse (1) What is data warehouse and what are the characteristics of data warehouse
win10 uwp modify picture quality compress picture
visual studio 2015 warning MSB3246
经验分享|盘点企业进行知识管理时的困惑类型
How to make good use of builder mode
某男子因用本地虚拟机做压测,惨遭字节面试官当场嘲笑
js数据类型、节流/防抖、点击事件委派优化、过渡动画
Win10 uwp use ScaleTransform magnify an element
C语言小笔记+题
【数据挖掘】搜狐公司数据挖掘工程师笔试题
括号匹配
dotnet enables JIT multi-core compilation to improve startup performance