forked from ardamavi/Vocalize-Sign-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_model.py
executable file
·67 lines (46 loc) · 1.86 KB
/
get_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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Arda Mavi
import os
from keras.models import Model
from database_process import get_data
from keras.layers import Input, Conv2D, Activation, MaxPooling2D, Flatten, Dense, Dropout
def save_model(model):
if not os.path.exists('Data/Model/'):
os.makedirs('Data/Model/')
model_json = model.to_json()
with open("Data/Model/model.json", "w") as model_file:
model_file.write(model_json)
# serialize weights to HDF5
model.save_weights("Data/Model/weights.h5")
print('Model and weights saved')
return
image_size = 64
channel_size = 1
def get_model():
num_class = len(get_data('SELECT id FROM "id_char"'))
inputs = Input(shape=(image_size, image_size, channel_size))
conv_1 = Conv2D(32, (3,3), strides=(1,1), padding='same')(inputs)
act_1 = Activation('relu')(conv_1)
conv_2 = Conv2D(64, (3,3), strides=(1,1), padding='same')(act_1)
act_2 = Activation('relu')(conv_2)
pooling_1 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(act_2)
conv_3 = Conv2D(64, (3,3), strides=(1,1), padding='same')(pooling_1)
act_3 = Activation('relu')(conv_3)
pooling_2 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(act_3)
conv_4 = Conv2D(128, (3,3), strides=(1,1), padding='same')(pooling_2)
act_4 = Activation('relu')(conv_4)
pooling_3 = MaxPooling2D(pool_size=(2, 2), strides=(2, 2))(act_4)
flat_1 = Flatten()(pooling_3)
fc = Dense(526)(flat_1)
fc = Activation('relu')(fc)
fc = Dropout(0.5)(fc)
fc = Dense(128)(fc)
fc = Activation('relu')(fc)
fc = Dropout(0.5)(fc)
fc = Dense(num_class)(fc)
outputs = Activation('softmax')(fc)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
print(model.summary())
return model
if __name__ == '__main__':
save_model(get_model())