GoogLeNet之InceptionV3神经网络简介与代码实战

1.介绍

Inception V3与Inception V2是来自于同一篇论文,具体可以参见论文Rethinking the Inception Architecture for Computer Vision中。

 

2.模型结构

GoogLeNet之InceptionV3神经网络简介与代码实战_第1张图片

                          InceptionV3 a子结构

GoogLeNet之InceptionV3神经网络简介与代码实战_第2张图片

                             InceptionV3 b子结构  

 

3.模型特点

Inception V3相比Inception V2进行了如下改进: 任意nxn的卷积都可以通过1xn卷积后接nx1卷积来替代,进一步减少参数量 ,但在实际上,作者发现在网络的前期使用这种分解效果并不好,只有在中度大小的feature map上使用效果才会更好,对于mxm大小的feature map,建议m在12到20之间。

 

4.代码实现 keras

def Conv2d(x, nb_filter, kernel_size, padding='same', strides=(1, 1)):
    x = Conv2D(nb_filter, kernel_size, padding=padding, strides=strides)(x)
    x = BatchNormalization(axis=3)(x)
    x = Activation('relu')(x)
    return x


def Inception_a(x, nb_filter=[128, 192]):
    branch0 = Conv2d(x, nb_filter[0], (1, 1), padding='same', strides=(1, 1))
    branch0 = Conv2d(branch0, nb_filter[0], (7, 1), padding='same', strides=(1, 1))
    branch0 = Conv2d(branch0, nb_filter[0], (1, 7), padding='same', strides=(1, 1))
    branch0 = Conv2d(branch0, nb_filter[0], (7, 1), padding='same', strides=(1, 1))
    branch0 = Conv2d(branch0, nb_filter[1], (1, 7), padding='same', strides=(1, 1))

    branch1 = Conv2d(x, nb_filter[0], (1, 1), padding='same', strides=(1, 1))
    branch1 = Conv2d(branch1, nb_filter[0], (7, 1), padding='same', strides=(1, 1))
    branch1 = Conv2d(branch1, nb_filter[1], (1, 7), padding='same', strides=(1, 1))
    
    branch2 = MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='same')(x)
    branch2 = Conv2d(branch2, nb_filter[1], (1, 1), padding='same', strides=(1, 1))
    
    branch3 = Conv2d(x, nb_filter[1], (1, 1), padding='same', strides=(1, 1))
    
    x = concatenate([branch0, branch1, branch2, branch3], axis=3)

    return x


def Inception_b(x, nb_filter=[448, 384, 192, 320]):
    branch0 = Conv2d(x, nb_filter[0], (1, 1), padding='same', strides=(1, 1))
    branch0 = Conv2d(branch0, nb_filter[1], (3, 3), padding='same', strides=(1, 1))
    branch0_1 = Conv2d(branch0, nb_filter[1], (3, 1), padding='same', strides=(1, 1))
    branch0_2 = Conv2d(branch0, nb_filter[1], (1, 3), padding='same', strides=(1, 1))

    branch1 = Conv2d(x, nb_filter[1], (1, 1), padding='same', strides=(1, 1))
    branch1_1 = Conv2d(branch1, nb_filter[1], (3, 1), padding='same', strides=(1, 1))
    branch1_2 = Conv2d(branch1, nb_filter[1], (1, 3), padding='same', strides=(1, 1))
    
    branch2 = MaxPooling2D(pool_size=(3, 3), strides=(1, 1), padding='same')(x)
    branch2 = Conv2d(branch2, nb_filter[2], (1, 1), padding='same', strides=(1, 1))
    
    branch3 = Conv2d(x, nb_filter[3], (1, 1), padding='same', strides=(1, 1))
    
    x = concatenate([branch0_1, branch0_2, branch1_1, branch1_2, branch2, branch3], axis=3)
    
    return x

 

你可能感兴趣的:(深度学习CNN基本模型,深度学习CNN基本模型)