-
Notifications
You must be signed in to change notification settings - Fork 38
/
model_arch.py
44 lines (33 loc) · 1.41 KB
/
model_arch.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
32
33
34
35
36
37
38
39
40
41
42
43
44
from keras.layers import Activation, AveragePooling2D, BatchNormalization, \
Convolution2D, Dense, Dropout, Flatten, Input, MaxPooling2D, Reshape
from keras.models import Model
from keras.layers.advanced_activations import ELU
def create_model(input_shape, class_count):
inputs = Input(shape=input_shape)
# add one more dimension for convolution
x = Reshape(input_shape + (1, ))(inputs)
x = BatchNormalization()(x)
def convolution_block(filter_count, dropout):
def create(x):
x = Convolution2D(filter_count, 3, 3, border_mode='same')(x)
x = BatchNormalization()(x)
x = ELU()(x)
x = Convolution2D(filter_count, 3, 3, border_mode='same')(x)
x = BatchNormalization()(x)
x = ELU()(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = Dropout(dropout)(x)
return x
return create
x = convolution_block(filter_count=32, dropout=0.1)(x)
x = convolution_block(filter_count=64, dropout=0.1)(x)
x = convolution_block(filter_count=64, dropout=0.1)(x)
x = convolution_block(filter_count=64, dropout=0.1)(x)
x = Flatten()(x)
x = Dense(class_count)(x)
x = BatchNormalization()(x)
predictions = Activation('softmax')(x)
model = Model(inputs, predictions)
model.compile(loss='categorical_crossentropy', optimizer='adam',
metrics=['accuracy'])
return model