forked from AmirmohmammadNouri/Facial-Smile-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
32 lines (27 loc) · 1.19 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
32
# Importing necessary libraries
from tensorflow.keras import Sequential, layers
from configparser import ConfigParser
# Reading Configuration Files
config = ConfigParser()
config.read("config.ini")
config_data = config["DEFAULT"]
# defining the Convolutional Neural Network
def initialize_model():
model = Sequential()
model.add(layers.Conv2D(32, (3, 3), activation="relu", input_shape=(int(config_data["image_height"]), int(config_data["image_width"]), int(config_data["image_depth"])), padding='same'))
model.add(layers.MaxPool2D(pool_size=(2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation="relu", padding='same'))
model.add(layers.MaxPool2D(pool_size=(2, 2)))
model.add(layers.Conv2D(128, (3, 3), activation="relu", padding='same'))
model.add(layers.MaxPool2D(pool_size=(3, 3)))
model.add(layers.Flatten())
model.add(layers.Dense(50, activation='relu'))
model.add(layers.Dropout(rate=0.2))
model.add(layers.Dense(1, activation='sigmoid'))
return model
# defining a function for compile the model
def compile_model(model):
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
return model