100天深度学习--PartA:Week1-day4 VGG

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

04_副本.png
04---副本.png

简介

VGG-Net是2014年ILSVRC classification第二名,top-5 错误率7.32%(第一名是GoogLeNet),ILSVRC localization 第一名。VGG-Net是由牛津大学视觉几何小组(Visual Geometry Group, VGG)提出,因此得名.

基本信息

论文 Very deep convolutional networks for large-scale image recognition

paper :https://arxiv.org/pdf/1409.1556.pdf

作者 Simonyan, Karen, and Andrew Zisserman

发表于 2015年 ICLR(International Conference On Learning Representations,)

翻译 http://www.aiqianji.com/blog/article/31

创新点

用简洁的方法设计了深层网络,所有 convolutional layer 使用同样大小的 convolutional filter,大小为 3 x 3

网络结构

VGG-Net 有五个stage,VGG-11 VGG-13 VGG-16 VGG-19

vgg.png

VGG的网络结构 分为五个stage, 不同层数的VGG,每个stage中的卷积层数目不同。
vgg.png

以VGG-16为例

网络层 输入尺寸 核尺寸 输出尺寸 参数个数
卷积层$C_{11}$ $224\times224\times3$ $3\times3\times64/1$ $224\times224\times64$ $(3\times3\times3+1)\times64$
卷积层$C_{12}$ $224\times224\times64$ $3\times3\times64/1$ $224\times224\times64$ $(3\times3\times64+1)\times64$
下采样层$S_{1}$ $224\times224\times64$ $2\times2/2$ $112\times112\times64$ $0$
卷积层$C_{21}$ $112\times112\times64$ $3\times3\times128/1$ $112\times112\times128$ $(3\times3\times64+1)\times128$
卷积层$C_{22}$ $112\times112\times128$ $3\times3\times128/1$ $112\times112\times128$ $(3\times3\times128+1)\times128$
下采样层$S_{2}$ $112\times112\times128$ $2\times2/2$ $56\times56\times128$ $0$
卷积层$C_{31}$ $56\times56\times128$ $3\times3\times256/1$ $56\times56\times256$ $(3\times3\times128+1)\times256$
卷积层$C_{32}$ $56\times56\times256$ $3\times3\times256/1$ $56\times56\times256$ $(3\times3\times256+1)\times256$
卷积层$C_{33}$ $56\times56\times256$ $3\times3\times256/1$ $56\times56\times256$ $(3\times3\times256+1)\times256$
下采样层$S_{3}$ $56\times56\times256$ $2\times2/2$ $28\times28\times256$ $0$
卷积层$C_{41}$ $28\times28\times256$ $3\times3\times512/1$ $28\times28\times512$ $(3\times3\times256+1)\times512$
卷积层$C_{42}$ $28\times28\times512$ $3\times3\times512/1$ $28\times28\times512$ $(3\times3\times512+1)\times512$
卷积层$C_{43}$ $28\times28\times512$ $3\times3\times512/1$ $28\times28\times512$ $(3\times3\times512+1)\times512$
下采样层$S_{4}$ $28\times28\times512$ $2\times2/2$ $14\times14\times512$ $0$
卷积层$C_{51}$ $14\times14\times512$ $3\times3\times512/1$ $14\times14\times512$ $(3\times3\times512+1)\times512$
卷积层$C_{52}$ $14\times14\times512$ $3\times3\times512/1$ $14\times14\times512$ $(3\times3\times512+1)\times512$
卷积层$C_{53}$ $14\times14\times512$ $3\times3\times512/1$ $14\times14\times512$ $(3\times3\times512+1)\times512$
下采样层$S_{5}$ $14\times14\times512$ $2\times2/2$ $7\times7\times512$ $0$
全连接层$FC_{1}$ $7\times7\times512$ $(7\times7\times512)\times4096$ $1\times4096$ $(7\times7\times512+1)\times4096$
全连接层$FC_{2}$ $1\times4096$ $4096\times4096$ $1\times4096$ $(4096+1)\times4096$
全连接层$FC_{3}$ $1\times4096$ $4096\times1000$ $1\times1000$ $(4096+1)\times1000$

抽象如图 :

04---副本-(2).png

数据变化如图

VGG16
vgg16_data.png

源码

tensorflow 源码: https://github.com/tensorflow/models/tree/master/research/slim/nets/vgg.py

caffe :

vgg16 https://gist.githubusercontent.com/ksimonyan/211839e770f7b538e2d8/raw/0067c9b32f60362c74f4c445a080beed06b07eb3/VGG_ILSVRC_16_layers_deploy.prototxt

vgg19 https://gist.githubusercontent.com/ksimonyan/3785162f95cd2d5fee77/raw/f02f8769e64494bcd3d7e97d5d747ac275825721/VGG_ILSVRC_19_layers_deploy.prototxt

pytorch :https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py

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

手写示例:

class VGG(nn.Module):
    def __init__(self, vgg_name):
        super(VGG, self).__init__()
        self.features = self._make_layers(cfg[vgg_name])
        self.classifier = nn.Linear(512, 10)

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

    def _make_layers(self, cfg):
        layers = []
        in_channels = 3
        for x in cfg:
            if x == 'M':
                layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
            else:
                layers += [nn.Conv2d(in_channels, x, kernel_size=3, padding=1),
                           nn.BatchNorm2d(x),
                           nn.ReLU(inplace=True)]
                in_channels = x
        layers += [nn.AvgPool2d(kernel_size=1, stride=1)]
        return nn.Sequential(*layers)

结果:
VGG11 BEST ACC. PERFORMANCE: 87.970%
VGG13 BEST ACC. PERFORMANCE: 90.200%
VGG16 BEST ACC. PERFORMANCE: 90.580%
VGG19 BEST ACC. PERFORMANCE: 90.610%