CNN常用模型 1 VGG16、2 Mobile_V1、3 Mobile_V2、 4 Mobile_V3

CNN 常用模型

  • 1. VGG16
    • 1.1 要点
    • 1.2 流程
    • 1.3 代码
  • 2 Mobile_V1
  • 3 Mobile_V2
  • 4 Mobile_V3

1. VGG16

1.1 要点

  1. 13个Con2d(kernel_size=3) + 5个MaxPooling(pool_size=2,strides=2)+3个Fc
  2. 第一Block有2个kernel=3x3,filters=64的Conv2D,1个MaxPool。
  3. 第二Block有2个kernel=3x3,filters=128的Conv2D,1个MaxPool。
  4. 第三Block有3个kernel=3x3,filters=256的Conv2D,1个MaxPool。
  5. 第四Block有3个kernel=3x3,filters=512的Conv2D,1个MaxPool。
  6. 第五Block有3个kernel=3x3,filters=512的Conv2D,1个MaxPool。
  7. 第六Block有3个Fc,1个SoftMax。
  8. 网络结构如下

inputs(224x224x3)# (None, 224, 224, 3) --> (None, 112, 112, 64)
Conv-63(f=63,k=3,s=1,p='s',a='relu')
Conv-63
MaxPool 
   ↓
# (None, 112, 112, 64) --> (None, 56, 56, 128)
Conv-128(f=128,k=3,s=1,p='s',a='relu')
Conv-128
MaxPool
   ↓
# (None, 56, 56, 128) --> (None, 28, 28, 256)
Conv-256(f=256,k=3,s=1,p='s',a='relu')
Conv-256
Conv-256
MaxPool
   ↓
# (None, 28, 28, 256) --> (None, 14, 14, 512)
Conv-512(f=512,k=3,s=1,p='s',a='relu')
Conv-512
Conv-512
MaxPool
   ↓
# (None, 14, 14, 512) --> (None, 7, 7, 512) 
Conv-512(f=512,k=3,s=1,p='s',a='relu')
Conv-512
Conv-512
MaxPool
   ↓
# (None, 7, 7, 512) --> (None, 1000) 
Fc(4096)(u=4096,a='relu')
Fc(4096)
Fc(1000)(u=1000)
SoftMax

1.2 流程

  1. 导入程序包
  2. 编写Converlution blocks
  3. 编写Dense layers
  4. 建立model

1.3 代码

# 1 Import
from keras import Model
from keras.utils import plot_model
from keras.layers import Input,Conv2D,BatchNormalization,MaxPool2D,Flatten,Dense,Dropout

# 2 Converlution blocks
input = Input(shape=(224,224,3))
# 2.1 1st block : (Conv-63)*2 + MaxPool
x = Conv2D(filters=64,kernel_size=3,padding='same',activation='relu')(input)
x = Conv2D(filters=64,kernel_size=3,padding='same',activation='relu')(x)
x = MaxPool2D(pool_size=2,strides=2,padding='same')(x)
# 2.2 2nd block : (Conv-128)*2 + MaxPool
x = Conv2D(filters=128,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=128,kernel_size=3,padding='same',activation='relu')(x)
x = MaxPool2D(pool_size=2,strides=2,padding='same')(x)
# 2.3 3rd block : (Conv-256)*3 + MaxPool
x = Conv2D(filters=256,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=256,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=256,kernel_size=3,padding='same',activation='relu')(x)
x = MaxPool2D(pool_size=2,strides=2,padding='same')(x)
# 2.4 4th block : (Conv-512)*3 + MaxPool
x = Conv2D(filters=512,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=512,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=512,kernel_size=3,padding='same',activation='relu')(x)
x = MaxPool2D(pool_size=2,strides=2,padding='same')(x)
# 2.5 5th block : (Conv-512)*3 + MaxPool
x = Conv2D(filters=512,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=512,kernel_size=3,padding='same',activation='relu')(x)
x = Conv2D(filters=512,kernel_size=3,padding='same',activation='relu')(x)
x = MaxPool2D(pool_size=2,strides=2,padding='same')(x)

# 3 Dense layers:Fc*3
x = Flatten()(x)
x = Dense(units = 4096,activation='relu')(x)
x = Dense(units = 4096,activation='relu')(x)
output = Dense(units = 1000,activation='softmax')(x)

# 4 Model
model = Model(inputs=input,outputs=output)
model.summary()
plot_model(model,show_shapes = True)

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 224, 224, 64)      1792      
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 224, 224, 64)      36928     
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 112, 112, 64)      0         
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 112, 112, 128)     73856     
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 112, 112, 128)     147584    
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 56, 56, 128)       0         
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 56, 56, 256)       295168    
_________________________________________________________________
conv2d_6 (Conv2D)            (None, 56, 56, 256)       590080    
_________________________________________________________________
conv2d_7 (Conv2D)            (None, 56, 56, 256)       590080    
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 28, 28, 256)       0         
_________________________________________________________________
conv2d_8 (Conv2D)            (None, 28, 28, 512)       1180160   
_________________________________________________________________
conv2d_9 (Conv2D)            (None, 28, 28, 512)       2359808   
_________________________________________________________________
conv2d_10 (Conv2D)           (None, 28, 28, 512)       2359808   
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 14, 14, 512)       0         
_________________________________________________________________
conv2d_11 (Conv2D)           (None, 14, 14, 512)       2359808   
_________________________________________________________________
conv2d_12 (Conv2D)           (None, 14, 14, 512)       2359808   
_________________________________________________________________
conv2d_13 (Conv2D)           (None, 14, 14, 512)       2359808   
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 7, 7, 512)         0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 25088)             0         
_________________________________________________________________
dense_1 (Dense)              (None, 4096)              102764544 
_________________________________________________________________
dense_2 (Dense)              (None, 4096)              16781312  
_________________________________________________________________
dense_3 (Dense)              (None, 1000)              4097000   
=================================================================
Total params: 138,357,544
Trainable params: 138,357,544
Non-trainable params: 0
_________________________________________________________________

Process finished with exit code 0

2 Mobile_V1

from keras import backend as K
from keras.models import Model
from keras.layers import DepthwiseConv2D,Input,Activation,Dropout,Reshape,BatchNormalization,GlobalAveragePooling2D,Conv2D


def _conv_block(inputs, filters, kernel=(3, 3), strides=(1, 1)):
    '''conv2D +BatchNormalization + Activation '''
    x = Conv2D(filters, kernel,
               padding='same',
               use_bias=False,
               strides=strides,
               name='conv1')(inputs)
    x = BatchNormalization(name='conv1_bn')(x)
    return Activation(relu6, name='conv1_relu')(x)


def _depthwise_conv_block(inputs, pointwise_conv_filters,
                          depth_multiplier=1, strides=(1, 1), block_id=1):
     '''DepthwiseConv2D+BatchNormalization + Activation +conv2D + B + A'''
    x = DepthwiseConv2D((3, 3),
                        padding='same',
                        depth_multiplier=depth_multiplier,
                        strides=strides,
                        use_bias=False,
                        name='conv_dw_%d' % block_id)(inputs)
    x = BatchNormalization(name='conv_dw_%d_bn' % block_id)(x)
    x = Activation(relu6, name='conv_dw_%d_relu' % block_id)(x)
    x = Conv2D(pointwise_conv_filters, (1, 1),
               padding='same',
               use_bias=False,
               strides=(1, 1),
               name='conv_pw_%d' % block_id)(x)
    x = BatchNormalization(name='conv_pw_%d_bn' % block_id)(x)
    return Activation(relu6, name='conv_pw_%d_relu' % block_id)(x)

def relu6(x):
    return K.relu(x, max_value=6)


def preprocess_input(x):
    x /= 255.
    x -= 0.5
    x *= 2.
    return x

def MobileNet(input_shape=[224,224,3],
              depth_multiplier=1,
              dropout=1e-3,
              classes=1000):
    img_input = Input(shape=input_shape)

    # 224,224,3 -> 112,112,32
    x = _conv_block(img_input, 32, strides=(2, 2))
    # 112,112,32 -> 112,112,64
    x = _depthwise_conv_block(x, 64, depth_multiplier, block_id=1)


    # 112,112,64 -> 56,56,128
    x = _depthwise_conv_block(x, 128, depth_multiplier,
                              strides=(2, 2), block_id=2)
    # 56,56,128 -> 56,56,128
    x = _depthwise_conv_block(x, 128, depth_multiplier, block_id=3)


    # 56,56,128 -> 28,28,256
    x = _depthwise_conv_block(x, 256, depth_multiplier,
                              strides=(2, 2), block_id=4)
    # 28,28,256 -> 28,28,256
    x = _depthwise_conv_block(x, 256, depth_multiplier, block_id=5)


    # 28,28,256 -> 14,14,512
    x = _depthwise_conv_block(x, 512, depth_multiplier,
                              strides=(2, 2), block_id=6)
    # 14,14,512 -> 14,14,512
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=7)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=8)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=9)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=10)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=11)

    # 14,14,512 -> 7,7,1024
    x = _depthwise_conv_block(x, 1024, depth_multiplier,
                              strides=(2, 2), block_id=12)
    x = _depthwise_conv_block(x, 1024, depth_multiplier, block_id=13)

    # 7,7,1024 -> 1,1,1024
    x = GlobalAveragePooling2D()(x)
    x = Reshape((1, 1, 1024), name='reshape_1')(x)
    x = Dropout(dropout, name='dropout')(x)

    x = Conv2D(classes, (1, 1),padding='same', name='conv_preds')(x)
    x = Activation('softmax', name='act_softmax')(x)
    x = Reshape((classes,), name='reshape_2')(x)

    inputs = img_input
    model = Model(inputs, x)

    return model



if __name__ == '__main__':
    model = MobileNet(input_shape=(224, 224, 3))
    model.summary()

'''
inputs:[224,224,3 ]
outputs:[1,1,000]
[224,224,3 ]-->_conv_block + _depthwise_conv_block-->
[112,112,64]-->_depthwise_conv_block*2 -->
[56,56,128]-->_depthwise_conv_block*2 -->
[28,28,256]-->_depthwise_conv_block-->
[14,14,512]-->_depthwise_conv_block*5-->
[14,14,512]-->_depthwise_conv_block*2-->
[ 7,7,1024]-->GlobalAveragePooling2D + Dropout-->
[ 1,1,1024]-->Conv2D + Activation-->[ 1, 1, 1000]
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
conv1 (Conv2D)               (None, 112, 112, 32)      864       
_________________________________________________________________
conv1_bn (BatchNormalization (None, 112, 112, 32)      128       
_________________________________________________________________
conv1_relu (Activation)      (None, 112, 112, 32)      0         
_________________________________________________________________
conv_dw_1 (DepthwiseConv2D)  (None, 112, 112, 32)      288       
_________________________________________________________________
conv_dw_1_bn (BatchNormaliza (None, 112, 112, 32)      128       
_________________________________________________________________
conv_dw_1_relu (Activation)  (None, 112, 112, 32)      0         
_________________________________________________________________
conv_pw_1 (Conv2D)           (None, 112, 112, 64)      2048      
_________________________________________________________________
conv_pw_1_bn (BatchNormaliza (None, 112, 112, 64)      256       
_________________________________________________________________
conv_pw_1_relu (Activation)  (None, 112, 112, 64)      0         
_________________________________________________________________
conv_dw_2 (DepthwiseConv2D)  (None, 56, 56, 64)        576       
_________________________________________________________________
conv_dw_2_bn (BatchNormaliza (None, 56, 56, 64)        256       
_________________________________________________________________
conv_dw_2_relu (Activation)  (None, 56, 56, 64)        0         
_________________________________________________________________
conv_pw_2 (Conv2D)           (None, 56, 56, 128)       8192      
_________________________________________________________________
conv_pw_2_bn (BatchNormaliza (None, 56, 56, 128)       512       
_________________________________________________________________
conv_pw_2_relu (Activation)  (None, 56, 56, 128)       0         
_________________________________________________________________
conv_dw_3 (DepthwiseConv2D)  (None, 56, 56, 128)       1152      
_________________________________________________________________
conv_dw_3_bn (BatchNormaliza (None, 56, 56, 128)       512       
_________________________________________________________________
conv_dw_3_relu (Activation)  (None, 56, 56, 128)       0         
_________________________________________________________________
conv_pw_3 (Conv2D)           (None, 56, 56, 128)       16384     
_________________________________________________________________
conv_pw_3_bn (BatchNormaliza (None, 56, 56, 128)       512       
_________________________________________________________________
conv_pw_3_relu (Activation)  (None, 56, 56, 128)       0         
_________________________________________________________________
conv_dw_4 (DepthwiseConv2D)  (None, 28, 28, 128)       1152      
_________________________________________________________________
conv_dw_4_bn (BatchNormaliza (None, 28, 28, 128)       512       
_________________________________________________________________
conv_dw_4_relu (Activation)  (None, 28, 28, 128)       0         
_________________________________________________________________
conv_pw_4 (Conv2D)           (None, 28, 28, 256)       32768     
_________________________________________________________________
conv_pw_4_bn (BatchNormaliza (None, 28, 28, 256)       1024      
_________________________________________________________________
conv_pw_4_relu (Activation)  (None, 28, 28, 256)       0         
_________________________________________________________________
conv_dw_5 (DepthwiseConv2D)  (None, 28, 28, 256)       2304      
_________________________________________________________________
conv_dw_5_bn (BatchNormaliza (None, 28, 28, 256)       1024      
_________________________________________________________________
conv_dw_5_relu (Activation)  (None, 28, 28, 256)       0         
_________________________________________________________________
conv_pw_5 (Conv2D)           (None, 28, 28, 256)       65536     
_________________________________________________________________
conv_pw_5_bn (BatchNormaliza (None, 28, 28, 256)       1024      
_________________________________________________________________
conv_pw_5_relu (Activation)  (None, 28, 28, 256)       0         
_________________________________________________________________
conv_dw_6 (DepthwiseConv2D)  (None, 14, 14, 256)       2304      
_________________________________________________________________
conv_dw_6_bn (BatchNormaliza (None, 14, 14, 256)       1024      
_________________________________________________________________
conv_dw_6_relu (Activation)  (None, 14, 14, 256)       0         
_________________________________________________________________
conv_pw_6 (Conv2D)           (None, 14, 14, 512)       131072    
_________________________________________________________________
conv_pw_6_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_6_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_7 (DepthwiseConv2D)  (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_7_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_7_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_7 (Conv2D)           (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_7_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_7_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_8 (DepthwiseConv2D)  (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_8_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_8_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_8 (Conv2D)           (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_8_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_8_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_9 (DepthwiseConv2D)  (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_9_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_9_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_9 (Conv2D)           (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_9_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_9_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_10 (DepthwiseConv2D) (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_10_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_10_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_10 (Conv2D)          (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_10_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_10_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_11 (DepthwiseConv2D) (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_11_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_11_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_11 (Conv2D)          (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_11_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_11_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_12 (DepthwiseConv2D) (None, 7, 7, 512)         4608      
_________________________________________________________________
conv_dw_12_bn (BatchNormaliz (None, 7, 7, 512)         2048      
_________________________________________________________________
conv_dw_12_relu (Activation) (None, 7, 7, 512)         0         
_________________________________________________________________
conv_pw_12 (Conv2D)          (None, 7, 7, 1024)        524288    
_________________________________________________________________
conv_pw_12_bn (BatchNormaliz (None, 7, 7, 1024)        4096      
_________________________________________________________________
conv_pw_12_relu (Activation) (None, 7, 7, 1024)        0         
_________________________________________________________________
conv_dw_13 (DepthwiseConv2D) (None, 7, 7, 1024)        9216      
_________________________________________________________________
conv_dw_13_bn (BatchNormaliz (None, 7, 7, 1024)        4096      
_________________________________________________________________
conv_dw_13_relu (Activation) (None, 7, 7, 1024)        0         
_________________________________________________________________
conv_pw_13 (Conv2D)          (None, 7, 7, 1024)        1048576   
_________________________________________________________________
conv_pw_13_bn (BatchNormaliz (None, 7, 7, 1024)        4096      
_________________________________________________________________
conv_pw_13_relu (Activation) (None, 7, 7, 1024)        0         
_________________________________________________________________
global_average_pooling2d_1 ( (None, 1024)              0         
_________________________________________________________________
reshape_1 (Reshape)          (None, 1, 1, 1024)        0         
_________________________________________________________________
dropout (Dropout)            (None, 1, 1, 1024)        0         
_________________________________________________________________
conv_preds (Conv2D)          (None, 1, 1, 1000)        1025000   
_________________________________________________________________
act_softmax (Activation)     (None, 1, 1, 1000)        0         
_________________________________________________________________
reshape_2 (Reshape)          (None, 1000)              0         
=================================================================
Total params: 4,253,864
Trainable params: 4,231,976
Non-trainable params: 21,888
_________________________________________________________________

Process finished with exit code 0

'''

3 Mobile_V2

from keras import backend as K
from keras.models import Model
from keras.layers import DepthwiseConv2D,Input,Activation,Dropout,Reshape,BatchNormalization,GlobalAveragePooling2D,Conv2D


def _conv_block(inputs, filters, kernel=(3, 3), strides=(1, 1)):
    '''conv2D +BatchNormalization + Activation '''
    x = Conv2D(filters, kernel,
               padding='same',
               use_bias=False,
               strides=strides,
               name='conv1')(inputs)
    x = BatchNormalization(name='conv1_bn')(x)
    return Activation(relu6, name='conv1_relu')(x)


def _depthwise_conv_block(inputs, pointwise_conv_filters,
                          depth_multiplier=1, strides=(1, 1), block_id=1):
     '''DepthwiseConv2D+BatchNormalization + Activation +conv2D + B + A'''
    x = DepthwiseConv2D((3, 3),
                        padding='same',
                        depth_multiplier=depth_multiplier,
                        strides=strides,
                        use_bias=False,
                        name='conv_dw_%d' % block_id)(inputs)
    x = BatchNormalization(name='conv_dw_%d_bn' % block_id)(x)
    x = Activation(relu6, name='conv_dw_%d_relu' % block_id)(x)
    x = Conv2D(pointwise_conv_filters, (1, 1),
               padding='same',
               use_bias=False,
               strides=(1, 1),
               name='conv_pw_%d' % block_id)(x)
    x = BatchNormalization(name='conv_pw_%d_bn' % block_id)(x)
    return Activation(relu6, name='conv_pw_%d_relu' % block_id)(x)

def relu6(x):
    return K.relu(x, max_value=6)


def preprocess_input(x):
    x /= 255.
    x -= 0.5
    x *= 2.
    return x

def MobileNet(input_shape=[224,224,3],
              depth_multiplier=1,
              dropout=1e-3,
              classes=1000):
    img_input = Input(shape=input_shape)

    # 224,224,3 -> 112,112,32
    x = _conv_block(img_input, 32, strides=(2, 2))
    # 112,112,32 -> 112,112,64
    x = _depthwise_conv_block(x, 64, depth_multiplier, block_id=1)


    # 112,112,64 -> 56,56,128
    x = _depthwise_conv_block(x, 128, depth_multiplier,
                              strides=(2, 2), block_id=2)
    # 56,56,128 -> 56,56,128
    x = _depthwise_conv_block(x, 128, depth_multiplier, block_id=3)


    # 56,56,128 -> 28,28,256
    x = _depthwise_conv_block(x, 256, depth_multiplier,
                              strides=(2, 2), block_id=4)
    # 28,28,256 -> 28,28,256
    x = _depthwise_conv_block(x, 256, depth_multiplier, block_id=5)


    # 28,28,256 -> 14,14,512
    x = _depthwise_conv_block(x, 512, depth_multiplier,
                              strides=(2, 2), block_id=6)
    # 14,14,512 -> 14,14,512
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=7)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=8)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=9)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=10)
    x = _depthwise_conv_block(x, 512, depth_multiplier, block_id=11)

    # 14,14,512 -> 7,7,1024
    x = _depthwise_conv_block(x, 1024, depth_multiplier,
                              strides=(2, 2), block_id=12)
    x = _depthwise_conv_block(x, 1024, depth_multiplier, block_id=13)

    # 7,7,1024 -> 1,1,1024
    x = GlobalAveragePooling2D()(x)
    x = Reshape((1, 1, 1024), name='reshape_1')(x)
    x = Dropout(dropout, name='dropout')(x)

    x = Conv2D(classes, (1, 1),padding='same', name='conv_preds')(x)
    x = Activation('softmax', name='act_softmax')(x)
    x = Reshape((classes,), name='reshape_2')(x)

    inputs = img_input
    model = Model(inputs, x)

    return model



if __name__ == '__main__':
    model = MobileNet(input_shape=(224, 224, 3))
    model.summary()

'''
inputs:[224,224,3 ]
outputs:[1,1,000]
[224,224,3 ]-->_conv_block + _depthwise_conv_block-->
[112,112,64]-->_depthwise_conv_block*2 -->
[56,56,128]-->_depthwise_conv_block*2 -->
[28,28,256]-->_depthwise_conv_block-->
[14,14,512]-->_depthwise_conv_block*5-->
[14,14,512]-->_depthwise_conv_block*2-->
[ 7,7,1024]-->GlobalAveragePooling2D + Dropout-->
[ 1,1,1024]-->Conv2D + Activation-->[ 1, 1, 1000]
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
conv1 (Conv2D)               (None, 112, 112, 32)      864       
_________________________________________________________________
conv1_bn (BatchNormalization (None, 112, 112, 32)      128       
_________________________________________________________________
conv1_relu (Activation)      (None, 112, 112, 32)      0         
_________________________________________________________________
conv_dw_1 (DepthwiseConv2D)  (None, 112, 112, 32)      288       
_________________________________________________________________
conv_dw_1_bn (BatchNormaliza (None, 112, 112, 32)      128       
_________________________________________________________________
conv_dw_1_relu (Activation)  (None, 112, 112, 32)      0         
_________________________________________________________________
conv_pw_1 (Conv2D)           (None, 112, 112, 64)      2048      
_________________________________________________________________
conv_pw_1_bn (BatchNormaliza (None, 112, 112, 64)      256       
_________________________________________________________________
conv_pw_1_relu (Activation)  (None, 112, 112, 64)      0         
_________________________________________________________________
conv_dw_2 (DepthwiseConv2D)  (None, 56, 56, 64)        576       
_________________________________________________________________
conv_dw_2_bn (BatchNormaliza (None, 56, 56, 64)        256       
_________________________________________________________________
conv_dw_2_relu (Activation)  (None, 56, 56, 64)        0         
_________________________________________________________________
conv_pw_2 (Conv2D)           (None, 56, 56, 128)       8192      
_________________________________________________________________
conv_pw_2_bn (BatchNormaliza (None, 56, 56, 128)       512       
_________________________________________________________________
conv_pw_2_relu (Activation)  (None, 56, 56, 128)       0         
_________________________________________________________________
conv_dw_3 (DepthwiseConv2D)  (None, 56, 56, 128)       1152      
_________________________________________________________________
conv_dw_3_bn (BatchNormaliza (None, 56, 56, 128)       512       
_________________________________________________________________
conv_dw_3_relu (Activation)  (None, 56, 56, 128)       0         
_________________________________________________________________
conv_pw_3 (Conv2D)           (None, 56, 56, 128)       16384     
_________________________________________________________________
conv_pw_3_bn (BatchNormaliza (None, 56, 56, 128)       512       
_________________________________________________________________
conv_pw_3_relu (Activation)  (None, 56, 56, 128)       0         
_________________________________________________________________
conv_dw_4 (DepthwiseConv2D)  (None, 28, 28, 128)       1152      
_________________________________________________________________
conv_dw_4_bn (BatchNormaliza (None, 28, 28, 128)       512       
_________________________________________________________________
conv_dw_4_relu (Activation)  (None, 28, 28, 128)       0         
_________________________________________________________________
conv_pw_4 (Conv2D)           (None, 28, 28, 256)       32768     
_________________________________________________________________
conv_pw_4_bn (BatchNormaliza (None, 28, 28, 256)       1024      
_________________________________________________________________
conv_pw_4_relu (Activation)  (None, 28, 28, 256)       0         
_________________________________________________________________
conv_dw_5 (DepthwiseConv2D)  (None, 28, 28, 256)       2304      
_________________________________________________________________
conv_dw_5_bn (BatchNormaliza (None, 28, 28, 256)       1024      
_________________________________________________________________
conv_dw_5_relu (Activation)  (None, 28, 28, 256)       0         
_________________________________________________________________
conv_pw_5 (Conv2D)           (None, 28, 28, 256)       65536     
_________________________________________________________________
conv_pw_5_bn (BatchNormaliza (None, 28, 28, 256)       1024      
_________________________________________________________________
conv_pw_5_relu (Activation)  (None, 28, 28, 256)       0         
_________________________________________________________________
conv_dw_6 (DepthwiseConv2D)  (None, 14, 14, 256)       2304      
_________________________________________________________________
conv_dw_6_bn (BatchNormaliza (None, 14, 14, 256)       1024      
_________________________________________________________________
conv_dw_6_relu (Activation)  (None, 14, 14, 256)       0         
_________________________________________________________________
conv_pw_6 (Conv2D)           (None, 14, 14, 512)       131072    
_________________________________________________________________
conv_pw_6_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_6_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_7 (DepthwiseConv2D)  (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_7_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_7_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_7 (Conv2D)           (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_7_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_7_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_8 (DepthwiseConv2D)  (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_8_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_8_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_8 (Conv2D)           (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_8_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_8_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_9 (DepthwiseConv2D)  (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_9_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_9_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_9 (Conv2D)           (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_9_bn (BatchNormaliza (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_9_relu (Activation)  (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_10 (DepthwiseConv2D) (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_10_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_10_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_10 (Conv2D)          (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_10_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_10_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_11 (DepthwiseConv2D) (None, 14, 14, 512)       4608      
_________________________________________________________________
conv_dw_11_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_dw_11_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_pw_11 (Conv2D)          (None, 14, 14, 512)       262144    
_________________________________________________________________
conv_pw_11_bn (BatchNormaliz (None, 14, 14, 512)       2048      
_________________________________________________________________
conv_pw_11_relu (Activation) (None, 14, 14, 512)       0         
_________________________________________________________________
conv_dw_12 (DepthwiseConv2D) (None, 7, 7, 512)         4608      
_________________________________________________________________
conv_dw_12_bn (BatchNormaliz (None, 7, 7, 512)         2048      
_________________________________________________________________
conv_dw_12_relu (Activation) (None, 7, 7, 512)         0         
_________________________________________________________________
conv_pw_12 (Conv2D)          (None, 7, 7, 1024)        524288    
_________________________________________________________________
conv_pw_12_bn (BatchNormaliz (None, 7, 7, 1024)        4096      
_________________________________________________________________
conv_pw_12_relu (Activation) (None, 7, 7, 1024)        0         
_________________________________________________________________
conv_dw_13 (DepthwiseConv2D) (None, 7, 7, 1024)        9216      
_________________________________________________________________
conv_dw_13_bn (BatchNormaliz (None, 7, 7, 1024)        4096      
_________________________________________________________________
conv_dw_13_relu (Activation) (None, 7, 7, 1024)        0         
_________________________________________________________________
conv_pw_13 (Conv2D)          (None, 7, 7, 1024)        1048576   
_________________________________________________________________
conv_pw_13_bn (BatchNormaliz (None, 7, 7, 1024)        4096      
_________________________________________________________________
conv_pw_13_relu (Activation) (None, 7, 7, 1024)        0         
_________________________________________________________________
global_average_pooling2d_1 ( (None, 1024)              0         
_________________________________________________________________
reshape_1 (Reshape)          (None, 1, 1, 1024)        0         
_________________________________________________________________
dropout (Dropout)            (None, 1, 1, 1024)        0         
_________________________________________________________________
conv_preds (Conv2D)          (None, 1, 1, 1000)        1025000   
_________________________________________________________________
act_softmax (Activation)     (None, 1, 1, 1000)        0         
_________________________________________________________________
reshape_2 (Reshape)          (None, 1000)              0         
=================================================================
Total params: 4,253,864
Trainable params: 4,231,976
Non-trainable params: 21,888
_________________________________________________________________

Process finished with exit code 0

'''

4 Mobile_V3


from keras.layers import Conv2D, DepthwiseConv2D, Dense, GlobalAveragePooling2D,Input
from keras.layers import Activation, BatchNormalization, Add, Multiply, Reshape
from keras.models import Model
from keras import backend as K

alpha = 1
def relu6(x):
    # relu函数
    return K.relu(x, max_value=6.0)

def hard_swish(x):
    # 利用relu函数乘上x模拟sigmoid
    return x * K.relu(x + 3.0, max_value=6.0) / 6.0

def return_activation(x, nl):
    # 用于判断使用哪个激活函数
    if nl == 'HS':
        x = Activation(hard_swish)(x)
    if nl == 'RE':
        x = Activation(relu6)(x)

    return x

def conv_block(inputs, filters, kernel, strides, nl):
    # 一个卷积单元,也就是conv2d + batchnormalization + activation
    channel_axis = 1 if K.image_data_format() == 'channels_first' else -1

    x = Conv2D(filters, kernel, padding='same', strides=strides)(inputs)
    x = BatchNormalization(axis=channel_axis)(x)

    return return_activation(x, nl)

def squeeze(inputs):
    # 注意力机制单元
    input_channels = int(inputs.shape[-1])

    x = GlobalAveragePooling2D()(inputs)
    x = Dense(int(input_channels/4))(x)
    x = Activation(relu6)(x)
    x = Dense(input_channels)(x)
    x = Activation(hard_swish)(x)
    x = Reshape((1, 1, input_channels))(x)
    x = Multiply()([inputs, x])

    return x

def bottleneck(inputs, filters, kernel, up_dim, stride, sq, nl):
    channel_axis = 1 if K.image_data_format() == 'channels_first' else -1

    input_shape = K.int_shape(inputs)

    tchannel = int(up_dim)
    cchannel = int(alpha * filters)

    r = stride == 1 and input_shape[3] == filters
    # 1x1卷积调整通道数,通道数上升
    x = conv_block(inputs, tchannel, (1, 1), (1, 1), nl)
    # 进行3x3深度可分离卷积
    x = DepthwiseConv2D(kernel, strides=(stride, stride), depth_multiplier=1, padding='same')(x)
    x = BatchNormalization(axis=channel_axis)(x)
    x = return_activation(x, nl)
    # 引入注意力机制
    if sq:
        x = squeeze(x)
    # 下降通道数
    x = Conv2D(cchannel, (1, 1), strides=(1, 1), padding='same')(x)
    x = BatchNormalization(axis=channel_axis)(x)


    if r:
        x = Add()([x, inputs])

    return x

def MobileNetv3_small(shape = (224,224,3),n_class = 1000):
    inputs = Input(shape)
    # 224,224,3 -> 112,112,16
    x = conv_block(inputs, 16, (3, 3), strides=(2, 2), nl='HS')

    # 112,112,16 -> 56,56,16
    x = bottleneck(x, 16, (3, 3), up_dim=16, stride=2, sq=True, nl='RE')

    # 56,56,16 -> 28,28,24
    x = bottleneck(x, 24, (3, 3), up_dim=72, stride=2, sq=False, nl='RE')
    x = bottleneck(x, 24, (3, 3), up_dim=88, stride=1, sq=False, nl='RE')
    
    # 28,28,24 -> 14,14,40
    x = bottleneck(x, 40, (5, 5), up_dim=96, stride=2, sq=True, nl='HS')
    x = bottleneck(x, 40, (5, 5), up_dim=240, stride=1, sq=True, nl='HS')
    x = bottleneck(x, 40, (5, 5), up_dim=240, stride=1, sq=True, nl='HS')
    # 14,14,40 -> 14,14,48
    x = bottleneck(x, 48, (5, 5), up_dim=120, stride=1, sq=True, nl='HS')
    x = bottleneck(x, 48, (5, 5), up_dim=144, stride=1, sq=True, nl='HS')

    # 14,14,48 -> 7,7,96
    x = bottleneck(x, 96, (5, 5), up_dim=288, stride=2, sq=True, nl='HS')
    x = bottleneck(x, 96, (5, 5), up_dim=576, stride=1, sq=True, nl='HS')
    x = bottleneck(x, 96, (5, 5), up_dim=576, stride=1, sq=True, nl='HS')
    
    # 7,7,96 -> 1, 1, 576
    x = conv_block(x, 576, (1, 1), strides=(1, 1), nl='HS')
    x = GlobalAveragePooling2D()(x)
    x = Reshape((1, 1, 576))(x)
    
    # 1, 1, 576 -> 1, 1, 1024
    x = Conv2D(1024, (1, 1), padding='same')(x)
    x = return_activation(x, 'HS')
    
    # 1, 1, 1024 -> 1, 1, 1000
    x = Conv2D(n_class, (1, 1), padding='same', activation='softmax')(x)
    x = Reshape((n_class,))(x)

    model = Model(inputs, x)

    return model
if __name__ == "__main__":
    model = MobileNetv3_small()
    model.summary()

'''
inputs: [224, 224, 3]
outputs: [None, 1000]
[224, 224, 3]-->conv_block-->[112,112,16]
[112,112,16]--> bottleneck-->[56,56,1656,56,16]
[56,56,16]-->bottleneck*2 -->[28,28,24]
[28,28,24]-->bottleneck*3 -->[14,14,40]
[14,14,40]-->bottleneck*2 -->[14,14,48]
[14,14,48]-->bottleneck*3 -->[7,7,96]
[7,7,96]--> conv_block + GlobalAveragePooling2D-->[1, 1, 576]
[1, 1, 576]-->Conv2D -->[1, 1, 1024]
[1, 1, 1024]-->>Conv2D -->[None, 1000]

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_1 (InputLayer)            (None, 224, 224, 3)  0                                            
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 112, 112, 16) 448         input_1[0][0]                    
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 112, 112, 16) 64          conv2d_1[0][0]                   
__________________________________________________________________________________________________
activation_1 (Activation)       (None, 112, 112, 16) 0           batch_normalization_1[0][0]      
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 112, 112, 16) 272         activation_1[0][0]               
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 112, 112, 16) 64          conv2d_2[0][0]                   
__________________________________________________________________________________________________
activation_2 (Activation)       (None, 112, 112, 16) 0           batch_normalization_2[0][0]      
__________________________________________________________________________________________________
depthwise_conv2d_1 (DepthwiseCo (None, 56, 56, 16)   160         activation_2[0][0]               
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 56, 56, 16)   64          depthwise_conv2d_1[0][0]         
__________________________________________________________________________________________________
activation_3 (Activation)       (None, 56, 56, 16)   0           batch_normalization_3[0][0]      
__________________________________________________________________________________________________
global_average_pooling2d_1 (Glo (None, 16)           0           activation_3[0][0]               
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 4)            68          global_average_pooling2d_1[0][0] 
__________________________________________________________________________________________________
activation_4 (Activation)       (None, 4)            0           dense_1[0][0]                    
__________________________________________________________________________________________________
dense_2 (Dense)                 (None, 16)           80          activation_4[0][0]               
__________________________________________________________________________________________________
activation_5 (Activation)       (None, 16)           0           dense_2[0][0]                    
__________________________________________________________________________________________________
reshape_1 (Reshape)             (None, 1, 1, 16)     0           activation_5[0][0]               
__________________________________________________________________________________________________
multiply_1 (Multiply)           (None, 56, 56, 16)   0           activation_3[0][0]               
                                                                 reshape_1[0][0]                  
__________________________________________________________________________________________________
conv2d_3 (Conv2D)               (None, 56, 56, 16)   272         multiply_1[0][0]                 
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 56, 56, 16)   64          conv2d_3[0][0]                   
__________________________________________________________________________________________________
conv2d_4 (Conv2D)               (None, 56, 56, 72)   1224        batch_normalization_4[0][0]      
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 56, 56, 72)   288         conv2d_4[0][0]                   
__________________________________________________________________________________________________
activation_6 (Activation)       (None, 56, 56, 72)   0           batch_normalization_5[0][0]      
__________________________________________________________________________________________________
depthwise_conv2d_2 (DepthwiseCo (None, 28, 28, 72)   720         activation_6[0][0]               
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 28, 28, 72)   288         depthwise_conv2d_2[0][0]         
__________________________________________________________________________________________________
activation_7 (Activation)       (None, 28, 28, 72)   0           batch_normalization_6[0][0]      
__________________________________________________________________________________________________
conv2d_5 (Conv2D)               (None, 28, 28, 24)   1752        activation_7[0][0]               
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 28, 28, 24)   96          conv2d_5[0][0]                   
__________________________________________________________________________________________________
conv2d_6 (Conv2D)               (None, 28, 28, 88)   2200        batch_normalization_7[0][0]      
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 28, 28, 88)   352         conv2d_6[0][0]                   
__________________________________________________________________________________________________
activation_8 (Activation)       (None, 28, 28, 88)   0           batch_normalization_8[0][0]      
__________________________________________________________________________________________________
depthwise_conv2d_3 (DepthwiseCo (None, 28, 28, 88)   880         activation_8[0][0]               
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 28, 28, 88)   352         depthwise_conv2d_3[0][0]         
__________________________________________________________________________________________________
activation_9 (Activation)       (None, 28, 28, 88)   0           batch_normalization_9[0][0]      
__________________________________________________________________________________________________
conv2d_7 (Conv2D)               (None, 28, 28, 24)   2136        activation_9[0][0]               
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 28, 28, 24)   96          conv2d_7[0][0]                   
__________________________________________________________________________________________________
add_1 (Add)                     (None, 28, 28, 24)   0           batch_normalization_10[0][0]     
                                                                 batch_normalization_7[0][0]      
__________________________________________________________________________________________________
conv2d_8 (Conv2D)               (None, 28, 28, 96)   2400        add_1[0][0]                      
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 28, 28, 96)   384         conv2d_8[0][0]                   
__________________________________________________________________________________________________
activation_10 (Activation)      (None, 28, 28, 96)   0           batch_normalization_11[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_4 (DepthwiseCo (None, 14, 14, 96)   2496        activation_10[0][0]              
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 14, 14, 96)   384         depthwise_conv2d_4[0][0]         
__________________________________________________________________________________________________
activation_11 (Activation)      (None, 14, 14, 96)   0           batch_normalization_12[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_2 (Glo (None, 96)           0           activation_11[0][0]              
__________________________________________________________________________________________________
dense_3 (Dense)                 (None, 24)           2328        global_average_pooling2d_2[0][0] 
__________________________________________________________________________________________________
activation_12 (Activation)      (None, 24)           0           dense_3[0][0]                    
__________________________________________________________________________________________________
dense_4 (Dense)                 (None, 96)           2400        activation_12[0][0]              
__________________________________________________________________________________________________
activation_13 (Activation)      (None, 96)           0           dense_4[0][0]                    
__________________________________________________________________________________________________
reshape_2 (Reshape)             (None, 1, 1, 96)     0           activation_13[0][0]              
__________________________________________________________________________________________________
multiply_2 (Multiply)           (None, 14, 14, 96)   0           activation_11[0][0]              
                                                                 reshape_2[0][0]                  
__________________________________________________________________________________________________
conv2d_9 (Conv2D)               (None, 14, 14, 40)   3880        multiply_2[0][0]                 
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 14, 14, 40)   160         conv2d_9[0][0]                   
__________________________________________________________________________________________________
conv2d_10 (Conv2D)              (None, 14, 14, 240)  9840        batch_normalization_13[0][0]     
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 14, 14, 240)  960         conv2d_10[0][0]                  
__________________________________________________________________________________________________
activation_14 (Activation)      (None, 14, 14, 240)  0           batch_normalization_14[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_5 (DepthwiseCo (None, 14, 14, 240)  6240        activation_14[0][0]              
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 14, 14, 240)  960         depthwise_conv2d_5[0][0]         
__________________________________________________________________________________________________
activation_15 (Activation)      (None, 14, 14, 240)  0           batch_normalization_15[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_3 (Glo (None, 240)          0           activation_15[0][0]              
__________________________________________________________________________________________________
dense_5 (Dense)                 (None, 60)           14460       global_average_pooling2d_3[0][0] 
__________________________________________________________________________________________________
activation_16 (Activation)      (None, 60)           0           dense_5[0][0]                    
__________________________________________________________________________________________________
dense_6 (Dense)                 (None, 240)          14640       activation_16[0][0]              
__________________________________________________________________________________________________
activation_17 (Activation)      (None, 240)          0           dense_6[0][0]                    
__________________________________________________________________________________________________
reshape_3 (Reshape)             (None, 1, 1, 240)    0           activation_17[0][0]              
__________________________________________________________________________________________________
multiply_3 (Multiply)           (None, 14, 14, 240)  0           activation_15[0][0]              
                                                                 reshape_3[0][0]                  
__________________________________________________________________________________________________
conv2d_11 (Conv2D)              (None, 14, 14, 40)   9640        multiply_3[0][0]                 
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 14, 14, 40)   160         conv2d_11[0][0]                  
__________________________________________________________________________________________________
add_2 (Add)                     (None, 14, 14, 40)   0           batch_normalization_16[0][0]     
                                                                 batch_normalization_13[0][0]     
__________________________________________________________________________________________________
conv2d_12 (Conv2D)              (None, 14, 14, 240)  9840        add_2[0][0]                      
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 14, 14, 240)  960         conv2d_12[0][0]                  
__________________________________________________________________________________________________
activation_18 (Activation)      (None, 14, 14, 240)  0           batch_normalization_17[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_6 (DepthwiseCo (None, 14, 14, 240)  6240        activation_18[0][0]              
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 14, 14, 240)  960         depthwise_conv2d_6[0][0]         
__________________________________________________________________________________________________
activation_19 (Activation)      (None, 14, 14, 240)  0           batch_normalization_18[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_4 (Glo (None, 240)          0           activation_19[0][0]              
__________________________________________________________________________________________________
dense_7 (Dense)                 (None, 60)           14460       global_average_pooling2d_4[0][0] 
__________________________________________________________________________________________________
activation_20 (Activation)      (None, 60)           0           dense_7[0][0]                    
__________________________________________________________________________________________________
dense_8 (Dense)                 (None, 240)          14640       activation_20[0][0]              
__________________________________________________________________________________________________
activation_21 (Activation)      (None, 240)          0           dense_8[0][0]                    
__________________________________________________________________________________________________
reshape_4 (Reshape)             (None, 1, 1, 240)    0           activation_21[0][0]              
__________________________________________________________________________________________________
multiply_4 (Multiply)           (None, 14, 14, 240)  0           activation_19[0][0]              
                                                                 reshape_4[0][0]                  
__________________________________________________________________________________________________
conv2d_13 (Conv2D)              (None, 14, 14, 40)   9640        multiply_4[0][0]                 
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 14, 14, 40)   160         conv2d_13[0][0]                  
__________________________________________________________________________________________________
add_3 (Add)                     (None, 14, 14, 40)   0           batch_normalization_19[0][0]     
                                                                 add_2[0][0]                      
__________________________________________________________________________________________________
conv2d_14 (Conv2D)              (None, 14, 14, 120)  4920        add_3[0][0]                      
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 14, 14, 120)  480         conv2d_14[0][0]                  
__________________________________________________________________________________________________
activation_22 (Activation)      (None, 14, 14, 120)  0           batch_normalization_20[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_7 (DepthwiseCo (None, 14, 14, 120)  3120        activation_22[0][0]              
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 14, 14, 120)  480         depthwise_conv2d_7[0][0]         
__________________________________________________________________________________________________
activation_23 (Activation)      (None, 14, 14, 120)  0           batch_normalization_21[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_5 (Glo (None, 120)          0           activation_23[0][0]              
__________________________________________________________________________________________________
dense_9 (Dense)                 (None, 30)           3630        global_average_pooling2d_5[0][0] 
__________________________________________________________________________________________________
activation_24 (Activation)      (None, 30)           0           dense_9[0][0]                    
__________________________________________________________________________________________________
dense_10 (Dense)                (None, 120)          3720        activation_24[0][0]              
__________________________________________________________________________________________________
activation_25 (Activation)      (None, 120)          0           dense_10[0][0]                   
__________________________________________________________________________________________________
reshape_5 (Reshape)             (None, 1, 1, 120)    0           activation_25[0][0]              
__________________________________________________________________________________________________
multiply_5 (Multiply)           (None, 14, 14, 120)  0           activation_23[0][0]              
                                                                 reshape_5[0][0]                  
__________________________________________________________________________________________________
conv2d_15 (Conv2D)              (None, 14, 14, 48)   5808        multiply_5[0][0]                 
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 14, 14, 48)   192         conv2d_15[0][0]                  
__________________________________________________________________________________________________
conv2d_16 (Conv2D)              (None, 14, 14, 144)  7056        batch_normalization_22[0][0]     
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 14, 14, 144)  576         conv2d_16[0][0]                  
__________________________________________________________________________________________________
activation_26 (Activation)      (None, 14, 14, 144)  0           batch_normalization_23[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_8 (DepthwiseCo (None, 14, 14, 144)  3744        activation_26[0][0]              
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 14, 14, 144)  576         depthwise_conv2d_8[0][0]         
__________________________________________________________________________________________________
activation_27 (Activation)      (None, 14, 14, 144)  0           batch_normalization_24[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_6 (Glo (None, 144)          0           activation_27[0][0]              
__________________________________________________________________________________________________
dense_11 (Dense)                (None, 36)           5220        global_average_pooling2d_6[0][0] 
__________________________________________________________________________________________________
activation_28 (Activation)      (None, 36)           0           dense_11[0][0]                   
__________________________________________________________________________________________________
dense_12 (Dense)                (None, 144)          5328        activation_28[0][0]              
__________________________________________________________________________________________________
activation_29 (Activation)      (None, 144)          0           dense_12[0][0]                   
__________________________________________________________________________________________________
reshape_6 (Reshape)             (None, 1, 1, 144)    0           activation_29[0][0]              
__________________________________________________________________________________________________
multiply_6 (Multiply)           (None, 14, 14, 144)  0           activation_27[0][0]              
                                                                 reshape_6[0][0]                  
__________________________________________________________________________________________________
conv2d_17 (Conv2D)              (None, 14, 14, 48)   6960        multiply_6[0][0]                 
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 14, 14, 48)   192         conv2d_17[0][0]                  
__________________________________________________________________________________________________
add_4 (Add)                     (None, 14, 14, 48)   0           batch_normalization_25[0][0]     
                                                                 batch_normalization_22[0][0]     
__________________________________________________________________________________________________
conv2d_18 (Conv2D)              (None, 14, 14, 288)  14112       add_4[0][0]                      
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 14, 14, 288)  1152        conv2d_18[0][0]                  
__________________________________________________________________________________________________
activation_30 (Activation)      (None, 14, 14, 288)  0           batch_normalization_26[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_9 (DepthwiseCo (None, 7, 7, 288)    7488        activation_30[0][0]              
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 7, 7, 288)    1152        depthwise_conv2d_9[0][0]         
__________________________________________________________________________________________________
activation_31 (Activation)      (None, 7, 7, 288)    0           batch_normalization_27[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_7 (Glo (None, 288)          0           activation_31[0][0]              
__________________________________________________________________________________________________
dense_13 (Dense)                (None, 72)           20808       global_average_pooling2d_7[0][0] 
__________________________________________________________________________________________________
activation_32 (Activation)      (None, 72)           0           dense_13[0][0]                   
__________________________________________________________________________________________________
dense_14 (Dense)                (None, 288)          21024       activation_32[0][0]              
__________________________________________________________________________________________________
activation_33 (Activation)      (None, 288)          0           dense_14[0][0]                   
__________________________________________________________________________________________________
reshape_7 (Reshape)             (None, 1, 1, 288)    0           activation_33[0][0]              
__________________________________________________________________________________________________
multiply_7 (Multiply)           (None, 7, 7, 288)    0           activation_31[0][0]              
                                                                 reshape_7[0][0]                  
__________________________________________________________________________________________________
conv2d_19 (Conv2D)              (None, 7, 7, 96)     27744       multiply_7[0][0]                 
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 7, 7, 96)     384         conv2d_19[0][0]                  
__________________________________________________________________________________________________
conv2d_20 (Conv2D)              (None, 7, 7, 576)    55872       batch_normalization_28[0][0]     
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 7, 7, 576)    2304        conv2d_20[0][0]                  
__________________________________________________________________________________________________
activation_34 (Activation)      (None, 7, 7, 576)    0           batch_normalization_29[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_10 (DepthwiseC (None, 7, 7, 576)    14976       activation_34[0][0]              
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 7, 7, 576)    2304        depthwise_conv2d_10[0][0]        
__________________________________________________________________________________________________
activation_35 (Activation)      (None, 7, 7, 576)    0           batch_normalization_30[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_8 (Glo (None, 576)          0           activation_35[0][0]              
__________________________________________________________________________________________________
dense_15 (Dense)                (None, 144)          83088       global_average_pooling2d_8[0][0] 
__________________________________________________________________________________________________
activation_36 (Activation)      (None, 144)          0           dense_15[0][0]                   
__________________________________________________________________________________________________
dense_16 (Dense)                (None, 576)          83520       activation_36[0][0]              
__________________________________________________________________________________________________
activation_37 (Activation)      (None, 576)          0           dense_16[0][0]                   
__________________________________________________________________________________________________
reshape_8 (Reshape)             (None, 1, 1, 576)    0           activation_37[0][0]              
__________________________________________________________________________________________________
multiply_8 (Multiply)           (None, 7, 7, 576)    0           activation_35[0][0]              
                                                                 reshape_8[0][0]                  
__________________________________________________________________________________________________
conv2d_21 (Conv2D)              (None, 7, 7, 96)     55392       multiply_8[0][0]                 
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 7, 7, 96)     384         conv2d_21[0][0]                  
__________________________________________________________________________________________________
add_5 (Add)                     (None, 7, 7, 96)     0           batch_normalization_31[0][0]     
                                                                 batch_normalization_28[0][0]     
__________________________________________________________________________________________________
conv2d_22 (Conv2D)              (None, 7, 7, 576)    55872       add_5[0][0]                      
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 7, 7, 576)    2304        conv2d_22[0][0]                  
__________________________________________________________________________________________________
activation_38 (Activation)      (None, 7, 7, 576)    0           batch_normalization_32[0][0]     
__________________________________________________________________________________________________
depthwise_conv2d_11 (DepthwiseC (None, 7, 7, 576)    14976       activation_38[0][0]              
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 7, 7, 576)    2304        depthwise_conv2d_11[0][0]        
__________________________________________________________________________________________________
activation_39 (Activation)      (None, 7, 7, 576)    0           batch_normalization_33[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_9 (Glo (None, 576)          0           activation_39[0][0]              
__________________________________________________________________________________________________
dense_17 (Dense)                (None, 144)          83088       global_average_pooling2d_9[0][0] 
__________________________________________________________________________________________________
activation_40 (Activation)      (None, 144)          0           dense_17[0][0]                   
__________________________________________________________________________________________________
dense_18 (Dense)                (None, 576)          83520       activation_40[0][0]              
__________________________________________________________________________________________________
activation_41 (Activation)      (None, 576)          0           dense_18[0][0]                   
__________________________________________________________________________________________________
reshape_9 (Reshape)             (None, 1, 1, 576)    0           activation_41[0][0]              
__________________________________________________________________________________________________
multiply_9 (Multiply)           (None, 7, 7, 576)    0           activation_39[0][0]              
                                                                 reshape_9[0][0]                  
__________________________________________________________________________________________________
conv2d_23 (Conv2D)              (None, 7, 7, 96)     55392       multiply_9[0][0]                 
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 7, 7, 96)     384         conv2d_23[0][0]                  
__________________________________________________________________________________________________
add_6 (Add)                     (None, 7, 7, 96)     0           batch_normalization_34[0][0]     
                                                                 add_5[0][0]                      
__________________________________________________________________________________________________
conv2d_24 (Conv2D)              (None, 7, 7, 576)    55872       add_6[0][0]                      
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 7, 7, 576)    2304        conv2d_24[0][0]                  
__________________________________________________________________________________________________
activation_42 (Activation)      (None, 7, 7, 576)    0           batch_normalization_35[0][0]     
__________________________________________________________________________________________________
global_average_pooling2d_10 (Gl (None, 576)          0           activation_42[0][0]              
__________________________________________________________________________________________________
reshape_10 (Reshape)            (None, 1, 1, 576)    0           global_average_pooling2d_10[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D)              (None, 1, 1, 1024)   590848      reshape_10[0][0]                 
__________________________________________________________________________________________________
activation_43 (Activation)      (None, 1, 1, 1024)   0           conv2d_25[0][0]                  
__________________________________________________________________________________________________
conv2d_26 (Conv2D)              (None, 1, 1, 1000)   1025000     activation_43[0][0]              
__________________________________________________________________________________________________
reshape_11 (Reshape)            (None, 1000)         0           conv2d_26[0][0]                  
==================================================================================================
Total params: 2,555,742
Trainable params: 2,543,598
Non-trainable params: 12,144
__________________________________________________________________________________________________

Process finished with exit code 0

'''

你可能感兴趣的:(计算机视觉)