-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
31 lines (29 loc) · 1.36 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import tensorflow as tf
from tensorflow.keras.layers import Input, Dense, ReLU, Conv2D, DepthwiseConv2D, GlobalAveragePooling2D, BatchNormalization
from tensorflow.keras import Model
def convolution_block(input_layer, strides, filters):
x = DepthwiseConv2D(kernel_size=3, strides=strides, padding='same')(input_layer)
x = BatchNormalization()(x)
x = ReLU()(x)
x = Conv2D(filters=filters, kernel_size=1, strides=1)(x)
x = BatchNormalization()(x)
x = ReLU()(x)
return x
def create_mobilenet(input_shape=(224, 224, 3), num_classes=1):
input_img = Input(shape=input_shape)
x = Conv2D(filters=32, kernel_size=(3,3), strides=(2,2), padding='same')(input_img)
x = BatchNormalization()(x)
x = ReLU()(x)
x = convolution_block(x, filters=64, strides=1)
x = convolution_block(x, filters=128, strides=2)
x = convolution_block(x, filters=128, strides=1)
x = convolution_block(x, filters=256, strides=2)
x = convolution_block(x, filters=256, strides=1)
x = convolution_block(x, filters=512, strides=2)
for _ in range(5):
x = convolution_block(x, filters=512, strides=1)
x = convolution_block(x, filters=1024, strides=2)
x = convolution_block(x, filters=1024, strides=1)
x = GlobalAveragePooling2D()(x)
out = Dense(units=num_classes, activation='sigmoid')(x)
return Model(inputs=input_img, outputs=out)