forked from NatiElgavi/Dog-Cat-Classifier
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_model.py
48 lines (35 loc) · 1.25 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
# Arda Mavi
import os
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
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
def get_model(num_classes=2):
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(64, 64, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
return model
if __name__ == '__main__':
save_model(get_model())