100天深度学习--PartA:Week1-day3 NIN

AI基础 经典网络  收藏
0 / 538

image.png

简介

2014年 ICLR 的paper,Network In Network(NIN),他对传统的CNN 网络进行了改进,大大减少参数数量,进一步提高了 CIFAR-10、CIFAR-100 等数据集上的准确率。对后来的模型设计起到了重要的作用。

image.png

基本信息

论文 Network In Network

paper :http://arxiv.org/abs/1312.4400

作者 Lin M, Chen Q, Yan S.

发表于 LCLR 2014

中文翻译 http://www.aiqianji.com/blog/article/15

创新点

能不能对卷积 进行改进,使得弄够拟合更复杂的函数?

1 Mlpconv Layer:Conv+MLP
提出在每个局部感受野中进行更加复杂的运算:MLP卷积层。 也就是叠加"micro network"网络,提高非线性表达。简单来说,就是叠加1X1的卷积层。

如何减少参数量?针对全连接层下手。

2 Global Average Pooling
传统的CNN最后一层都是全连接层,参数非常多,容易引起过拟合。作者提出采用了:全局均值池化,替代全连接层。

网络结构

image.png

网络层 输入尺寸 核尺寸 输出尺寸 可训练参数量
卷积层$C_1$ $^*$ $224\times224\times3$ $11\times11\times3/4,96$ $55\times55\times96$ $(11\times11\times3+1)\times96\times2$
CCCP1 $55\times55\times96$ $1\times1\times96$ $55\times55\times96$
CCCP2 $55\times55\times96$ $1\times1\times96$ $55\times55\times96$
下采样层$S$$^*$ $55\times55\times96$ $3\times3/2$ $27\times27\times96$ 0
卷积层$C_2$ $27\times27\times96$ $5\times5\times96/1,256$ $27\times27\times256$ $(5\times5\times96+1)\times256\times2$
CCCP3 $27\times27\times256$ $1\times1\times256$ $27\times27\times256$
CCCP4 $27\times27\times256$ $1\times1\times256$ $27\times27\times256$
下采样层$S$ $27\times27\times256$ $3\times3/2$ $13\times13\times256$ 0
卷积层$C_3$ $^*$ $13\times13\times256$ $3\times3\times256/1,384$ $13\times13\times384$ $(3\times3\times256+1)\times384\times2$
CCCP5 $13\times13\times384$ $1\times1\times384$ $13\times13\times384$
CCCP6 $13\times13\times384$ $1\times1\times384$ $13\times13\times384$
下采样层$S$ $13\times13\times384$ $3\times3/2$ $6\times6\times384$ 0
卷积层$C_4$ $^*$ $6\times6\times384$ $3\times3\times384/1,1024$ $6\times6\times1024$ $(3\times3\times384+1)\times1024\times2$
CCCP7 $6\times6\times1024$ $1\times1\times1024$ $6\times6\times1024$
CCCP8 $6\times6\times1024$ $1\times1\times1000$ $6\times6\times1000$

NIN也可以方便的用在其他网络结构中:
image.png

image.png

##源码

caffe: https://gist.github.com/mavenlin/d802a5849de39225bcc6

tensorflow: https://github.com/tflearn/tflearn/blob/master/examples/images/network_in_network.py

练习:在32*32 的 cifar10 上进行十分类,用pytorch构建网络结构

手写示例:

class NIN(nn.Module):
    def __init__(self, num_classes=NUM_CLASSES):
        super(NIN, self).__init__()
        self.features = nn.Sequential(
            nn.Conv2d(3, 64, kernel_size=3, stride=2, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(64, 64, kernel_size=1, stride=1),
            nn.ReLU(inplace=True),     
            nn.Conv2d(64, 64, kernel_size=1, stride=1),
            nn.ReLU(inplace=True),                     
            nn.MaxPool2d(kernel_size=2),

            nn.Conv2d(64, 192, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(192, 192, kernel_size=1, stride=1),
            nn.ReLU(inplace=True),      
            nn.Conv2d(192, 192, kernel_size=1, stride=1),
            nn.ReLU(inplace=True),                          
            nn.MaxPool2d(kernel_size=2),

            nn.Conv2d(192, 384, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(384, 384, kernel_size=1, stride=1),
            nn.ReLU(inplace=True),  
            nn.Conv2d(384, 256, kernel_size=1, stride=1),
            nn.ReLU(inplace=True),           
            nn.AvgPool2d(kernel_size=4),
        )

        self.classifier = nn.Linear(256, 10)

    def forward(self, x):
        x = self.features(x)
        x = x.view(x.size(0),-1)
        x = self.classifier(x)
        return x

结果:
BEST ACC. PERFORMANCE: 76.570%

相关拓展:

paper : Batch-normalized Maxout Network in Network

arxiv: http://arxiv.org/abs/1511.02583

知识点

1x1卷积对channel维度上的元素做乘加操作. 如图所示,

由于1x1卷积对空间维度上的元素并没有做关联,所以空间维度(h,w)上的信息得以传递到后面的层中.
举个例子,以[h,w,c]这种顺序为例,1x1卷积只会将[0,0,0],[0,0,1],[0,0,2]做乘加操作.