VGG
VGG-16和VGG-19取名源自作者所处研究组名(Visual Geometry Group),后面的16 19代表了网络的深度。
VGG-16/VGG-19 138M参数,ILSVRC 2014的亚军网络。
VGG-16结构的基本框架
conv1^2 (64) -> pool1 -> conv2^2 (128) -> pool2 -> conv3^3 (256) -> pool3 -> conv4^3 (512) -> pool4 -> conv5^3 (512) -> pool5 -> fc6 (4096) -> fc7 (4096) -> fc8 (1000) -> softmax。 ^3代表重复3次。
网络输入的224×224的图像。
def VGG16(images, _dropout, n_cls):
"""
此处权重初始化方式采用的是:
卷积层使用预训练模型中的参数
全连接层使用xavier类型初始化
"""
conv1_1 = conv(images, 64, 'conv1_1', fineturn=True) #1
conv1_2 = conv(conv1_1, 64, 'conv1_2', fineturn=True) #2
pool1 = maxpool(conv1_2, 'pool1')
conv2_1 = conv(pool1, 128, 'conv2_1', fineturn=True) #3
conv2_2 = conv(conv2_1, 128, 'conv2_2', fineturn=True) #4
pool2 = maxpool(conv2_2, 'pool2')
conv3_1 = conv(pool2, 256, 'conv3_1', fineturn=True) #5
conv3_2 = conv(conv3_1, 256, 'conv3_2', fineturn=True) #6
conv3_3 = conv(conv3_2, 256, 'conv3_3', fineturn=True) #7
pool3 = maxpool(conv3_3, 'pool3')
conv4_1 = conv(pool3, 512, 'conv4_1', fineturn=True) #8
conv4_2 = conv(conv4_1, 512, 'conv4_2', fineturn=True) #9
conv4_3 = conv(conv4_2, 512, 'conv4_3', fineturn=True) #10
pool4 = maxpool(conv4_3, 'pool4')
conv5_1 = conv(pool4, 512, 'conv5_1', fineturn=True) #11
conv5_2 = conv(conv5_1, 512, 'conv5_2', fineturn=True) #12
conv5_3 = conv(conv5_2, 512, 'conv5_3', fineturn=True) #13
pool5 = maxpool(conv5_3, 'pool5')
#因为训练自己的数据,全连接层最好不要使用预训练参数
flatten = tf.reshape(pool5, [-1, 7*7*512])
fc6 = fc(flatten, 4096, 'fc6', xavier=True) #14
dropout1 = tf.nn.dropout(fc6, _dropout)
fc7 = fc(dropout1, 4096, 'fc7', xavier=True) #15
dropout2 = tf.nn.dropout(fc7, _dropout)
fc8 = fc(dropout2, n_cls, 'fc8', xavier=True) #16
return fc8
VGG网络的特点
(1). 结构简单,只有3×3卷积和2×2汇合两种配置,并且重复堆叠相同的模块组合。卷积层不改变空间大小,每经过一次汇合层,空间大小减半。
(2). 参数量大,而且大部分的参数集中在全连接层中。网络名称中有16表示它有16层conv/fc层。
(3). 合适的网络初始化和使用批量归一(batch normalization)层对训练深层网络很重要。
(4). VGG-19结构类似于VGG-16,有略好于VGG-16的性能,但VGG-19需要消耗更大的资源,因此实际中VGG-16使用得更多。由于VGG-16网络结构十分简单,并且很适合迁移学习,因此至今VGG-16仍在广泛使用。