Directory
Features and benefits of MobileNet
Synopsis
MobileNet is a compact and efficient CNN model proposed by Google, which makes a compromise between accuracy and latency. The model is suitable for use on mobile devices and meets the real-time requirement in daily life.
Features
There are two innovative points in the proposal of MobileNetV1:
- Depthwise Convolution.
- Superparameters α and β.
The characteristic of Depthwise convolution is that the size of the convolution kernel is 1, and the number of the input eigenmatrix is the number of the convolution kernel and the number of the output eigenmatrix. In general, Depthwise convolution convolved with Pointwise convolution. Pointwise convolution is actually ordinary convolution, but it adopts 1x1 convolution kernel. And that makes them 1/8 as much computation as normal convolution. What’s more, we can get a smaller model by adjusting the values of α and β.
MobileNetV2 makes two improvements over MobileNetV1:
- Inverted Resduals.
- Linear Bottlenecks.
MobileNetV1 uses the residual block, while MobileNetV2 uses the inverted residual block. This structure is just the opposite of the traditional residual block in which the dimension is first reduced and then amplified, so the shotcut also becomes the feature map connected with the dimension reduced. Linear Bottlenecks. In other words, the nonlinear activation layer behind the small dimension output layer was removed to ensure the expression ability of the model.
The structure of MobileNetV2
This is the basic structure of MobileNetV2 in the paper, and t is extended factor, and n is the bottleneck of repetitions. The inverted residual block, bottleneck, is as follows:
Among them, it is worth noting that stride of the bottleneck structure is only be set in the first time, the rest of the stride is 1. As for the applicable condition of shortcut, the paper only indicates the condition of stride = 1. However, when the code is implemented, I find that the result is inconsistent with the structure diagram. Therefore, I infer that this is an error in the paper. And then, after analysis, I find that if there is no shortcut, it will not affect the result. Therefore, it is inferred that the condition of n > 1 is still missing.
Using keras to implemented MobileNetV2
Code:
from keras.models import Model
from keras.layers import Input, Conv2D, GlobalAveragePooling2D, Dropout, DepthwiseConv2D
from keras.layers import Activation, BatchNormalization, Reshape, add
from keras import backend
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
def relu6(x):
relu_6 = backend.relu(x, max_value=6)
return relu_6
def _conv_layer(inputs, filters, kernel, strides):
channel_axis = 1 if backend.image_data_format() == 'channels_first' else -1
x = Conv2D(filters, kernel, padding='same', strides=strides)(inputs)
x = BatchNormalization(axis=channel_axis)(x)
x = Activation(relu6)(x)
return x
def _bottleneck(inputs, filters, kernel, t, strides, r=False):
channel_axis = 1 if backend.image_data_format() == 'channels_first' else -1
t_channel = backend.int_shape(inputs)[channel_axis] * t
# input shape (h, w, k)
# Convolution layer 1 output shape (h, w, tk)
x = _conv_layer(inputs, t_channel, (1, 1), (1, 1))
# DW convolution layer 2 output shape (h/s, w/s, tk)
x = DepthwiseConv2D(kernel, strides=(strides, strides), depth_multiplier=1, padding='same')(x)
x = BatchNormalization(axis=channel_axis)(x)
x = Activation(relu6)(x)
# Convolution layer 3 output shape (h/s, w/s, filters)
x = Conv2D(filters, (1, 1), strides=(1, 1), padding='same')(x)
x = BatchNormalization(axis=channel_axis)(x)
x = Activation('linear')(x)
if r:
x = add([x, inputs])
return x
def _bottleneck_layer(inputs, filters, kernel, t, strides, n):
x = _bottleneck(inputs, filters, kernel, t, strides)
for i in range(1, n):
# In addition to the first layer, other bottleneck layers of strides is 1
x = _bottleneck(x, filters, kernel, t, 1, True)
return x
def MobileNetv2(input_shape, k):
# Assume that the input shape is (224, 224, 3)
inputs = Input(shape=input_shape)
# Convolution layer 1 output shape (112, 112, 32)
x = _conv_layer(inputs, 32, (3, 3), strides=(2, 2))
# Bottleneck layer 2 output shape (112, 112, 16)
x = _bottleneck_layer(x, 16, (3, 3), t=1, strides=1, n=1)
# Bottleneck layer 3 output shape (56, 56, 24)
x = _bottleneck_layer(x, 24, (3, 3), t=6, strides=2, n=2)
# Bottleneck layer 4 output shape (28, 28, 32)
x = _bottleneck_layer(x, 32, (3, 3), t=6, strides=2, n=3)
# Bottleneck layer 5 output shape (14, 14, 64)
x = _bottleneck_layer(x, 64, (3, 3), t=6, strides=2, n=4)
# Bottleneck layer 6 output shape (14, 14, 96)
x = _bottleneck_layer(x, 96, (3, 3), t=6, strides=1, n=3)
# Bottleneck layer 7 output shape (7, 7, 160)
x = _bottleneck_layer(x, 160, (3, 3), t=6, strides=2, n=3)
# Bottleneck layer 8 output shape (7, 7, 320)
x = _bottleneck_layer(x, 320, (3, 3), t=6, strides=1, n=1)
# Convolution layer 9 output shape (7, 7, 1280)
x = _conv_layer(x, 1280, (1, 1), strides=(1, 1))
# Averagepooling layer 10 output shape (1, 1, 1280)
x = GlobalAveragePooling2D()(x)
x = Reshape((1, 1, 1280))(x)
x = Dropout(0.3, name='Dropout')(x)
# Convolution layer 10 output class k
x = Conv2D(k, (1, 1), padding='same')(x)
x = Activation('softmax', name='softmax')(x)
outputs = Reshape((k,))(x)
model = Model(inputs, outputs)
return model
if __name__ == '__main__':
# Take the ImageNet dataset as an example
model = MobileNetv2((224, 224, 3), 1000)
model.summary()
Result: Since the data set of ImageNet cannot be downloaded from the official website, the relevant experiment cannot be carried out temporarily.
Model: "model_1"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_1 (InputLayer) (None, 224, 224, 3) 0
__________________________________________________________________________________________________
conv2d_1 (Conv2D) (None, 112, 112, 32) 896 input_1[0][0]
__________________________________________________________________________________________________
batch_normalization_1 (BatchNor (None, 112, 112, 32) 128 conv2d_1[0][0]
__________________________________________________________________________________________________
activation_1 (Activation) (None, 112, 112, 32) 0 batch_normalization_1[0][0]
__________________________________________________________________________________________________
conv2d_2 (Conv2D) (None, 112, 112, 32) 1056 activation_1[0][0]
__________________________________________________________________________________________________
batch_normalization_2 (BatchNor (None, 112, 112, 32) 128 conv2d_2[0][0]
__________________________________________________________________________________________________
activation_2 (Activation) (None, 112, 112, 32) 0 batch_normalization_2[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_1 (DepthwiseCo (None, 112, 112, 32) 320 activation_2[0][0]
__________________________________________________________________________________________________
batch_normalization_3 (BatchNor (None, 112, 112, 32) 128 depthwise_conv2d_1[0][0]
__________________________________________________________________________________________________
activation_3 (Activation) (None, 112, 112, 32) 0 batch_normalization_3[0][0]
__________________________________________________________________________________________________
conv2d_3 (Conv2D) (None, 112, 112, 16) 528 activation_3[0][0]
__________________________________________________________________________________________________
batch_normalization_4 (BatchNor (None, 112, 112, 16) 64 conv2d_3[0][0]
__________________________________________________________________________________________________
activation_4 (Activation) (None, 112, 112, 16) 0 batch_normalization_4[0][0]
__________________________________________________________________________________________________
conv2d_4 (Conv2D) (None, 112, 112, 96) 1632 activation_4[0][0]
__________________________________________________________________________________________________
batch_normalization_5 (BatchNor (None, 112, 112, 96) 384 conv2d_4[0][0]
__________________________________________________________________________________________________
activation_5 (Activation) (None, 112, 112, 96) 0 batch_normalization_5[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_2 (DepthwiseCo (None, 56, 56, 96) 960 activation_5[0][0]
__________________________________________________________________________________________________
batch_normalization_6 (BatchNor (None, 56, 56, 96) 384 depthwise_conv2d_2[0][0]
__________________________________________________________________________________________________
activation_6 (Activation) (None, 56, 56, 96) 0 batch_normalization_6[0][0]
__________________________________________________________________________________________________
conv2d_5 (Conv2D) (None, 56, 56, 24) 2328 activation_6[0][0]
__________________________________________________________________________________________________
batch_normalization_7 (BatchNor (None, 56, 56, 24) 96 conv2d_5[0][0]
__________________________________________________________________________________________________
activation_7 (Activation) (None, 56, 56, 24) 0 batch_normalization_7[0][0]
__________________________________________________________________________________________________
conv2d_6 (Conv2D) (None, 56, 56, 144) 3600 activation_7[0][0]
__________________________________________________________________________________________________
batch_normalization_8 (BatchNor (None, 56, 56, 144) 576 conv2d_6[0][0]
__________________________________________________________________________________________________
activation_8 (Activation) (None, 56, 56, 144) 0 batch_normalization_8[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_3 (DepthwiseCo (None, 56, 56, 144) 1440 activation_8[0][0]
__________________________________________________________________________________________________
batch_normalization_9 (BatchNor (None, 56, 56, 144) 576 depthwise_conv2d_3[0][0]
__________________________________________________________________________________________________
activation_9 (Activation) (None, 56, 56, 144) 0 batch_normalization_9[0][0]
__________________________________________________________________________________________________
conv2d_7 (Conv2D) (None, 56, 56, 24) 3480 activation_9[0][0]
__________________________________________________________________________________________________
batch_normalization_10 (BatchNo (None, 56, 56, 24) 96 conv2d_7[0][0]
__________________________________________________________________________________________________
activation_10 (Activation) (None, 56, 56, 24) 0 batch_normalization_10[0][0]
__________________________________________________________________________________________________
add_1 (Add) (None, 56, 56, 24) 0 activation_10[0][0]
activation_7[0][0]
__________________________________________________________________________________________________
conv2d_8 (Conv2D) (None, 56, 56, 144) 3600 add_1[0][0]
__________________________________________________________________________________________________
batch_normalization_11 (BatchNo (None, 56, 56, 144) 576 conv2d_8[0][0]
__________________________________________________________________________________________________
activation_11 (Activation) (None, 56, 56, 144) 0 batch_normalization_11[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_4 (DepthwiseCo (None, 28, 28, 144) 1440 activation_11[0][0]
__________________________________________________________________________________________________
batch_normalization_12 (BatchNo (None, 28, 28, 144) 576 depthwise_conv2d_4[0][0]
__________________________________________________________________________________________________
activation_12 (Activation) (None, 28, 28, 144) 0 batch_normalization_12[0][0]
__________________________________________________________________________________________________
conv2d_9 (Conv2D) (None, 28, 28, 32) 4640 activation_12[0][0]
__________________________________________________________________________________________________
batch_normalization_13 (BatchNo (None, 28, 28, 32) 128 conv2d_9[0][0]
__________________________________________________________________________________________________
activation_13 (Activation) (None, 28, 28, 32) 0 batch_normalization_13[0][0]
__________________________________________________________________________________________________
conv2d_10 (Conv2D) (None, 28, 28, 192) 6336 activation_13[0][0]
__________________________________________________________________________________________________
batch_normalization_14 (BatchNo (None, 28, 28, 192) 768 conv2d_10[0][0]
__________________________________________________________________________________________________
activation_14 (Activation) (None, 28, 28, 192) 0 batch_normalization_14[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_5 (DepthwiseCo (None, 28, 28, 192) 1920 activation_14[0][0]
__________________________________________________________________________________________________
batch_normalization_15 (BatchNo (None, 28, 28, 192) 768 depthwise_conv2d_5[0][0]
__________________________________________________________________________________________________
activation_15 (Activation) (None, 28, 28, 192) 0 batch_normalization_15[0][0]
__________________________________________________________________________________________________
conv2d_11 (Conv2D) (None, 28, 28, 32) 6176 activation_15[0][0]
__________________________________________________________________________________________________
batch_normalization_16 (BatchNo (None, 28, 28, 32) 128 conv2d_11[0][0]
__________________________________________________________________________________________________
activation_16 (Activation) (None, 28, 28, 32) 0 batch_normalization_16[0][0]
__________________________________________________________________________________________________
add_2 (Add) (None, 28, 28, 32) 0 activation_16[0][0]
activation_13[0][0]
__________________________________________________________________________________________________
conv2d_12 (Conv2D) (None, 28, 28, 192) 6336 add_2[0][0]
__________________________________________________________________________________________________
batch_normalization_17 (BatchNo (None, 28, 28, 192) 768 conv2d_12[0][0]
__________________________________________________________________________________________________
activation_17 (Activation) (None, 28, 28, 192) 0 batch_normalization_17[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_6 (DepthwiseCo (None, 28, 28, 192) 1920 activation_17[0][0]
__________________________________________________________________________________________________
batch_normalization_18 (BatchNo (None, 28, 28, 192) 768 depthwise_conv2d_6[0][0]
__________________________________________________________________________________________________
activation_18 (Activation) (None, 28, 28, 192) 0 batch_normalization_18[0][0]
__________________________________________________________________________________________________
conv2d_13 (Conv2D) (None, 28, 28, 32) 6176 activation_18[0][0]
__________________________________________________________________________________________________
batch_normalization_19 (BatchNo (None, 28, 28, 32) 128 conv2d_13[0][0]
__________________________________________________________________________________________________
activation_19 (Activation) (None, 28, 28, 32) 0 batch_normalization_19[0][0]
__________________________________________________________________________________________________
add_3 (Add) (None, 28, 28, 32) 0 activation_19[0][0]
add_2[0][0]
__________________________________________________________________________________________________
conv2d_14 (Conv2D) (None, 28, 28, 192) 6336 add_3[0][0]
__________________________________________________________________________________________________
batch_normalization_20 (BatchNo (None, 28, 28, 192) 768 conv2d_14[0][0]
__________________________________________________________________________________________________
activation_20 (Activation) (None, 28, 28, 192) 0 batch_normalization_20[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_7 (DepthwiseCo (None, 14, 14, 192) 1920 activation_20[0][0]
__________________________________________________________________________________________________
batch_normalization_21 (BatchNo (None, 14, 14, 192) 768 depthwise_conv2d_7[0][0]
__________________________________________________________________________________________________
activation_21 (Activation) (None, 14, 14, 192) 0 batch_normalization_21[0][0]
__________________________________________________________________________________________________
conv2d_15 (Conv2D) (None, 14, 14, 64) 12352 activation_21[0][0]
__________________________________________________________________________________________________
batch_normalization_22 (BatchNo (None, 14, 14, 64) 256 conv2d_15[0][0]
__________________________________________________________________________________________________
activation_22 (Activation) (None, 14, 14, 64) 0 batch_normalization_22[0][0]
__________________________________________________________________________________________________
conv2d_16 (Conv2D) (None, 14, 14, 384) 24960 activation_22[0][0]
__________________________________________________________________________________________________
batch_normalization_23 (BatchNo (None, 14, 14, 384) 1536 conv2d_16[0][0]
__________________________________________________________________________________________________
activation_23 (Activation) (None, 14, 14, 384) 0 batch_normalization_23[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_8 (DepthwiseCo (None, 14, 14, 384) 3840 activation_23[0][0]
__________________________________________________________________________________________________
batch_normalization_24 (BatchNo (None, 14, 14, 384) 1536 depthwise_conv2d_8[0][0]
__________________________________________________________________________________________________
activation_24 (Activation) (None, 14, 14, 384) 0 batch_normalization_24[0][0]
__________________________________________________________________________________________________
conv2d_17 (Conv2D) (None, 14, 14, 64) 24640 activation_24[0][0]
__________________________________________________________________________________________________
batch_normalization_25 (BatchNo (None, 14, 14, 64) 256 conv2d_17[0][0]
__________________________________________________________________________________________________
activation_25 (Activation) (None, 14, 14, 64) 0 batch_normalization_25[0][0]
__________________________________________________________________________________________________
add_4 (Add) (None, 14, 14, 64) 0 activation_25[0][0]
activation_22[0][0]
__________________________________________________________________________________________________
conv2d_18 (Conv2D) (None, 14, 14, 384) 24960 add_4[0][0]
__________________________________________________________________________________________________
batch_normalization_26 (BatchNo (None, 14, 14, 384) 1536 conv2d_18[0][0]
__________________________________________________________________________________________________
activation_26 (Activation) (None, 14, 14, 384) 0 batch_normalization_26[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_9 (DepthwiseCo (None, 14, 14, 384) 3840 activation_26[0][0]
__________________________________________________________________________________________________
batch_normalization_27 (BatchNo (None, 14, 14, 384) 1536 depthwise_conv2d_9[0][0]
__________________________________________________________________________________________________
activation_27 (Activation) (None, 14, 14, 384) 0 batch_normalization_27[0][0]
__________________________________________________________________________________________________
conv2d_19 (Conv2D) (None, 14, 14, 64) 24640 activation_27[0][0]
__________________________________________________________________________________________________
batch_normalization_28 (BatchNo (None, 14, 14, 64) 256 conv2d_19[0][0]
__________________________________________________________________________________________________
activation_28 (Activation) (None, 14, 14, 64) 0 batch_normalization_28[0][0]
__________________________________________________________________________________________________
add_5 (Add) (None, 14, 14, 64) 0 activation_28[0][0]
add_4[0][0]
__________________________________________________________________________________________________
conv2d_20 (Conv2D) (None, 14, 14, 384) 24960 add_5[0][0]
__________________________________________________________________________________________________
batch_normalization_29 (BatchNo (None, 14, 14, 384) 1536 conv2d_20[0][0]
__________________________________________________________________________________________________
activation_29 (Activation) (None, 14, 14, 384) 0 batch_normalization_29[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_10 (DepthwiseC (None, 14, 14, 384) 3840 activation_29[0][0]
__________________________________________________________________________________________________
batch_normalization_30 (BatchNo (None, 14, 14, 384) 1536 depthwise_conv2d_10[0][0]
__________________________________________________________________________________________________
activation_30 (Activation) (None, 14, 14, 384) 0 batch_normalization_30[0][0]
__________________________________________________________________________________________________
conv2d_21 (Conv2D) (None, 14, 14, 64) 24640 activation_30[0][0]
__________________________________________________________________________________________________
batch_normalization_31 (BatchNo (None, 14, 14, 64) 256 conv2d_21[0][0]
__________________________________________________________________________________________________
activation_31 (Activation) (None, 14, 14, 64) 0 batch_normalization_31[0][0]
__________________________________________________________________________________________________
add_6 (Add) (None, 14, 14, 64) 0 activation_31[0][0]
add_5[0][0]
__________________________________________________________________________________________________
conv2d_22 (Conv2D) (None, 14, 14, 384) 24960 add_6[0][0]
__________________________________________________________________________________________________
batch_normalization_32 (BatchNo (None, 14, 14, 384) 1536 conv2d_22[0][0]
__________________________________________________________________________________________________
activation_32 (Activation) (None, 14, 14, 384) 0 batch_normalization_32[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_11 (DepthwiseC (None, 14, 14, 384) 3840 activation_32[0][0]
__________________________________________________________________________________________________
batch_normalization_33 (BatchNo (None, 14, 14, 384) 1536 depthwise_conv2d_11[0][0]
__________________________________________________________________________________________________
activation_33 (Activation) (None, 14, 14, 384) 0 batch_normalization_33[0][0]
__________________________________________________________________________________________________
conv2d_23 (Conv2D) (None, 14, 14, 96) 36960 activation_33[0][0]
__________________________________________________________________________________________________
batch_normalization_34 (BatchNo (None, 14, 14, 96) 384 conv2d_23[0][0]
__________________________________________________________________________________________________
activation_34 (Activation) (None, 14, 14, 96) 0 batch_normalization_34[0][0]
__________________________________________________________________________________________________
conv2d_24 (Conv2D) (None, 14, 14, 576) 55872 activation_34[0][0]
__________________________________________________________________________________________________
batch_normalization_35 (BatchNo (None, 14, 14, 576) 2304 conv2d_24[0][0]
__________________________________________________________________________________________________
activation_35 (Activation) (None, 14, 14, 576) 0 batch_normalization_35[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_12 (DepthwiseC (None, 14, 14, 576) 5760 activation_35[0][0]
__________________________________________________________________________________________________
batch_normalization_36 (BatchNo (None, 14, 14, 576) 2304 depthwise_conv2d_12[0][0]
__________________________________________________________________________________________________
activation_36 (Activation) (None, 14, 14, 576) 0 batch_normalization_36[0][0]
__________________________________________________________________________________________________
conv2d_25 (Conv2D) (None, 14, 14, 96) 55392 activation_36[0][0]
__________________________________________________________________________________________________
batch_normalization_37 (BatchNo (None, 14, 14, 96) 384 conv2d_25[0][0]
__________________________________________________________________________________________________
activation_37 (Activation) (None, 14, 14, 96) 0 batch_normalization_37[0][0]
__________________________________________________________________________________________________
add_7 (Add) (None, 14, 14, 96) 0 activation_37[0][0]
activation_34[0][0]
__________________________________________________________________________________________________
conv2d_26 (Conv2D) (None, 14, 14, 576) 55872 add_7[0][0]
__________________________________________________________________________________________________
batch_normalization_38 (BatchNo (None, 14, 14, 576) 2304 conv2d_26[0][0]
__________________________________________________________________________________________________
activation_38 (Activation) (None, 14, 14, 576) 0 batch_normalization_38[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_13 (DepthwiseC (None, 14, 14, 576) 5760 activation_38[0][0]
__________________________________________________________________________________________________
batch_normalization_39 (BatchNo (None, 14, 14, 576) 2304 depthwise_conv2d_13[0][0]
__________________________________________________________________________________________________
activation_39 (Activation) (None, 14, 14, 576) 0 batch_normalization_39[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D) (None, 14, 14, 96) 55392 activation_39[0][0]
__________________________________________________________________________________________________
batch_normalization_40 (BatchNo (None, 14, 14, 96) 384 conv2d_27[0][0]
__________________________________________________________________________________________________
activation_40 (Activation) (None, 14, 14, 96) 0 batch_normalization_40[0][0]
__________________________________________________________________________________________________
add_8 (Add) (None, 14, 14, 96) 0 activation_40[0][0]
add_7[0][0]
__________________________________________________________________________________________________
conv2d_28 (Conv2D) (None, 14, 14, 576) 55872 add_8[0][0]
__________________________________________________________________________________________________
batch_normalization_41 (BatchNo (None, 14, 14, 576) 2304 conv2d_28[0][0]
__________________________________________________________________________________________________
activation_41 (Activation) (None, 14, 14, 576) 0 batch_normalization_41[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_14 (DepthwiseC (None, 7, 7, 576) 5760 activation_41[0][0]
__________________________________________________________________________________________________
batch_normalization_42 (BatchNo (None, 7, 7, 576) 2304 depthwise_conv2d_14[0][0]
__________________________________________________________________________________________________
activation_42 (Activation) (None, 7, 7, 576) 0 batch_normalization_42[0][0]
__________________________________________________________________________________________________
conv2d_29 (Conv2D) (None, 7, 7, 160) 92320 activation_42[0][0]
__________________________________________________________________________________________________
batch_normalization_43 (BatchNo (None, 7, 7, 160) 640 conv2d_29[0][0]
__________________________________________________________________________________________________
activation_43 (Activation) (None, 7, 7, 160) 0 batch_normalization_43[0][0]
__________________________________________________________________________________________________
conv2d_30 (Conv2D) (None, 7, 7, 960) 154560 activation_43[0][0]
__________________________________________________________________________________________________
batch_normalization_44 (BatchNo (None, 7, 7, 960) 3840 conv2d_30[0][0]
__________________________________________________________________________________________________
activation_44 (Activation) (None, 7, 7, 960) 0 batch_normalization_44[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_15 (DepthwiseC (None, 7, 7, 960) 9600 activation_44[0][0]
__________________________________________________________________________________________________
batch_normalization_45 (BatchNo (None, 7, 7, 960) 3840 depthwise_conv2d_15[0][0]
__________________________________________________________________________________________________
activation_45 (Activation) (None, 7, 7, 960) 0 batch_normalization_45[0][0]
__________________________________________________________________________________________________
conv2d_31 (Conv2D) (None, 7, 7, 160) 153760 activation_45[0][0]
__________________________________________________________________________________________________
batch_normalization_46 (BatchNo (None, 7, 7, 160) 640 conv2d_31[0][0]
__________________________________________________________________________________________________
activation_46 (Activation) (None, 7, 7, 160) 0 batch_normalization_46[0][0]
__________________________________________________________________________________________________
add_9 (Add) (None, 7, 7, 160) 0 activation_46[0][0]
activation_43[0][0]
__________________________________________________________________________________________________
conv2d_32 (Conv2D) (None, 7, 7, 960) 154560 add_9[0][0]
__________________________________________________________________________________________________
batch_normalization_47 (BatchNo (None, 7, 7, 960) 3840 conv2d_32[0][0]
__________________________________________________________________________________________________
activation_47 (Activation) (None, 7, 7, 960) 0 batch_normalization_47[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_16 (DepthwiseC (None, 7, 7, 960) 9600 activation_47[0][0]
__________________________________________________________________________________________________
batch_normalization_48 (BatchNo (None, 7, 7, 960) 3840 depthwise_conv2d_16[0][0]
__________________________________________________________________________________________________
activation_48 (Activation) (None, 7, 7, 960) 0 batch_normalization_48[0][0]
__________________________________________________________________________________________________
conv2d_33 (Conv2D) (None, 7, 7, 160) 153760 activation_48[0][0]
__________________________________________________________________________________________________
batch_normalization_49 (BatchNo (None, 7, 7, 160) 640 conv2d_33[0][0]
__________________________________________________________________________________________________
activation_49 (Activation) (None, 7, 7, 160) 0 batch_normalization_49[0][0]
__________________________________________________________________________________________________
add_10 (Add) (None, 7, 7, 160) 0 activation_49[0][0]
add_9[0][0]
__________________________________________________________________________________________________
conv2d_34 (Conv2D) (None, 7, 7, 960) 154560 add_10[0][0]
__________________________________________________________________________________________________
batch_normalization_50 (BatchNo (None, 7, 7, 960) 3840 conv2d_34[0][0]
__________________________________________________________________________________________________
activation_50 (Activation) (None, 7, 7, 960) 0 batch_normalization_50[0][0]
__________________________________________________________________________________________________
depthwise_conv2d_17 (DepthwiseC (None, 7, 7, 960) 9600 activation_50[0][0]
__________________________________________________________________________________________________
batch_normalization_51 (BatchNo (None, 7, 7, 960) 3840 depthwise_conv2d_17[0][0]
__________________________________________________________________________________________________
activation_51 (Activation) (None, 7, 7, 960) 0 batch_normalization_51[0][0]
__________________________________________________________________________________________________
conv2d_35 (Conv2D) (None, 7, 7, 320) 307520 activation_51[0][0]
__________________________________________________________________________________________________
batch_normalization_52 (BatchNo (None, 7, 7, 320) 1280 conv2d_35[0][0]
__________________________________________________________________________________________________
activation_52 (Activation) (None, 7, 7, 320) 0 batch_normalization_52[0][0]
__________________________________________________________________________________________________
conv2d_36 (Conv2D) (None, 7, 7, 1280) 410880 activation_52[0][0]
__________________________________________________________________________________________________
batch_normalization_53 (BatchNo (None, 7, 7, 1280) 5120 conv2d_36[0][0]
__________________________________________________________________________________________________
activation_53 (Activation) (None, 7, 7, 1280) 0 batch_normalization_53[0][0]
__________________________________________________________________________________________________
global_average_pooling2d_1 (Glo (None, 1280) 0 activation_53[0][0]
__________________________________________________________________________________________________
reshape_1 (Reshape) (None, 1, 1, 1280) 0 global_average_pooling2d_1[0][0]
__________________________________________________________________________________________________
Dropout (Dropout) (None, 1, 1, 1280) 0 reshape_1[0][0]
__________________________________________________________________________________________________
conv2d_37 (Conv2D) (None, 1, 1, 1000) 1281000 Dropout[0][0]
__________________________________________________________________________________________________
softmax (Activation) (None, 1, 1, 1000) 0 conv2d_37[0][0]
__________________________________________________________________________________________________
reshape_2 (Reshape) (None, 1000) 0 softmax[0][0]
==================================================================================================
Total params: 3,557,224
Trainable params: 3,523,048
Non-trainable params: 34,176
__________________________________________________________________________________________________
Conclusion
MobileNetV2 can train a model that is similar in accuracy to ordinary CNN, but lighter than ordinary CNN. Next, I will try to apply the mobilenet network to the detection of fire and smoke.
Reference
- MobileNet网络详解
- 徐梓涵,刘军,张苏沛,肖澳文,杜壮.一种基于MobileNet的火灾烟雾检测方法[J].武汉工程大学学报,2019,41(06):580-585.
XU Zihan,LIUJun,ZHANG Supei,XIAO Aowen,DU Zhuang.Fire and Smoke Detection Method Based on MobileNet[J]. Journal of Wuhan Institute of Technology,2019,41(06):580-585.