深度学习(07)-- 经典CNN网络结构(Inception (v1-v4))
文章目录
目录
1.Inception介绍
1.1 Inception结构
1.2 Inception V1(GoogleNet)
Naive Inception
Inception Module
GoogLeNet
1.3 Inception V2(Batch Norm)
1.4 Inception V3(Factorization)
1.5 Inception V4(ResNet)
Inception V4 相比 V3 主要是结合了微软的 ResNet,将错误率进一步减少到 3.08%。
1.5 Inception v1~v4 总结
1.6 Inception进阶
Inception v4 、Inception ResNet v1、Inception ResNet v2
Inception V4 网络模型 Vs Inception ResNet 模型:
2.Inception实现
inceptionV2
def Conv2d_BN(x, filters, kernel_size, padding='same', strides=(1,1), name=None):
if name is not None:
bn_name = name + '_bn'
conv_name = name + '_conv'
else:
bn_name = None
conv_name = None
x = Conv2D(filters=filters, kernel_size=kernel_size, padding=padding, strides=strides, activation='relu', name=conv_name)(x)
x = BatchNormalization(axis=3, name=bn_name)(x)
return x
def Inception(x, filters):
branch_1x1 = Conv2d_BN(x, filters=filters, kernel_size=(1,1), padding='same', strides=(1,1), name=None)
branch_3x3 = Conv2d_BN(x, filters=filters, kernel_size=(1,1), padding='same', strides=(1,1), name=None)
branch_3x3 = Conv2d_BN(branch_3x3, filters=filters, kernel_size=(3,3), padding='same', strides=(1,1), name=None)
branch_5x5 = Conv2d_BN(x, filters=filters, kernel_size=(1,1), padding='same', strides=(1,1), name=None)
branch_5x5 = Conv2d_BN(branch_5x5, filters=filters, kernel_size=(5,5), padding='same', strides=(1,1), name=None)
branch_pool = MaxPooling2D(pool_size=(3,3), strides=(1,1), padding='same')(x)
branch_pool = Conv2d_BN(branch_pool, filters=filters, kernel_size=(1,1), padding='same', strides=(1,1), name=None)
x = concatenate([branch_1x1, branch_3x3, branch_5x5, branch_pool], axis=3)
return x
def Inception_v2(input_shape=(64,64,3), classes=6):
x_input = Input(input_shape)
"stage 1: "
x = Conv2d_BN(x_input, filters=4, kernel_size=(5,5), strides=(1,1), padding='same')
x = MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same')(x)
x = Conv2d_BN(x, filters=8, kernel_size=(1,1), strides=(1,1), padding='same')
x = Conv2d_BN(x, filters=8, kernel_size=(3,3), strides=(1,1), padding='same')
x = MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same')(x)
"stage 2: Inception_v2_block (*2)"
x = Inception(x, 16) #4*16=64
x = Inception(x, 16)
x = MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same')(x)
"stage 3: Inception_v2_block (*5)"
x = Inception(x, 32)
x = Inception(x, 32)
x = Inception(x, 32)
x = Inception(x, 64)
x = Inception(x, 64)
x = MaxPooling2D(pool_size=(3,3), strides=(2,2), padding='same')(x)
"stage 4: Inception_v2_block (*2)"
x = Inception(x, 128)
x = Inception(x, 128)
x = AveragePooling2D(pool_size=(4,4), strides=(1,1), padding='same')(x)
x = Flatten()(x)
"stage 5: fc"
x = Dropout(0.5)(x)
x = Dense(6,activation='softmax')(x)
model = Model(inputs=x_input, outputs=x, name='Inception_v2')
return model