def create_inception_resnet_v2(nb_classes=1001, scale=True):
'''
Creates a inception resnet v2 network
:param nb_classes: number of classes.txt
:param scale: flag to add scaling of activations
:return: Keras Model with 1 input (299x299x3) input shape and 2 outputs (final_output, auxiliary_output)
'''
if K.image_dim_ordering() == 'th':
init = Input((3, 299, 299))
else:
init = Input((299, 299, 3))
# Input Shape is 299 x 299 x 3 (tf) or 3 x 299 x 299 (th)
x = inception_resnet_stem(init)
# 10 x Inception Resnet A
for i in range(10):
x = inception_resnet_v2_A(x, scale_residual=scale)
# Reduction A
x = reduction_A(x, k=256, l=256, m=384, n=384)
# 20 x Inception Resnet B
for i in range(20):
x = inception_resnet_v2_B(x, scale_residual=scale)
# Auxiliary tower
aux_out = AveragePooling2D((5, 5), strides=(3, 3))(x)
aux_out = Convolution2D(128, 1, 1, border_mode='same', activation='relu')(aux_out)
aux_out = Convolution2D(768, 5, 5, activation='relu')(aux_out)
aux_out = Flatten()(aux_out)
aux_out = Dense(nb_classes, activation='softmax')(aux_out)
# Reduction Resnet B
x = reduction_resnet_v2_B(x)
# 10 x Inception Resnet C
for i in range(10):
x = inception_resnet_v2_C(x, scale_residual=scale)
# Average Pooling
x = AveragePooling2D((8,8))(x)
# Dropout
x = Dropout(0.8)(x)
x = Flatten()(x)
# Output
out = Dense(output_dim=nb_classes, activation='softmax')(x)
model = Model(init, output=[out, aux_out], name='Inception-Resnet-v2')
return model
评论列表
文章目录