gruhit-patel
commited on
Commit
•
a85377e
1
Parent(s):
e6b1756
Update model.py
Browse files
model.py
CHANGED
@@ -1,39 +1,39 @@
|
|
1 |
-
import os
|
2 |
-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
3 |
-
|
4 |
-
import keras
|
5 |
-
from keras.layers import Input, Dropout, Dense
|
6 |
-
from keras.models import Model
|
7 |
-
from keras_vggface.vggface import VGGFace
|
8 |
-
|
9 |
-
def get_model(image_shape, num_classes, model_weights, unfreeze_layers=-3, drop_rate=0.5):
|
10 |
-
|
11 |
-
input_layer = Input(shape=image_shape)
|
12 |
-
vgg_base_model = VGGFace(include_top = False, input_shape = image_shape, pooling='avg')
|
13 |
-
|
14 |
-
# Freeze all the layers till unfreeze layers
|
15 |
-
for layer in vgg_base_model.layers[:unfreeze_layers]:
|
16 |
-
layer.trainable =
|
17 |
-
|
18 |
-
for layer in vgg_base_model.layers[unfreeze_layers:]:
|
19 |
-
|
20 |
-
|
21 |
-
x = vgg_base_model(input_layer)
|
22 |
-
|
23 |
-
x = Dropout(drop_rate)(x)
|
24 |
-
output = Dense(num_classes, activation='softmax')(x)
|
25 |
-
|
26 |
-
model = Model(inputs=[input_layer], outputs=[output], name="Expression_Classifier")
|
27 |
-
model.load_weights(model_weights)
|
28 |
-
return model
|
29 |
-
|
30 |
-
|
31 |
-
if __name__ == "__main__":
|
32 |
-
model_path = "vgg_face_weights2.h5"
|
33 |
-
model = get_model(
|
34 |
-
image_shape = (224, 224, 3),
|
35 |
-
num_classes = 6,
|
36 |
-
model_weights = model_path
|
37 |
-
)
|
38 |
-
|
39 |
print(model.summary())
|
|
|
1 |
+
import os
|
2 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
3 |
+
|
4 |
+
import keras
|
5 |
+
from keras.layers import Input, Dropout, Dense
|
6 |
+
from keras.models import Model
|
7 |
+
from keras_vggface.vggface import VGGFace
|
8 |
+
|
9 |
+
def get_model(image_shape, num_classes, model_weights, unfreeze_layers=-3, drop_rate=0.5):
|
10 |
+
|
11 |
+
input_layer = Input(shape=image_shape)
|
12 |
+
vgg_base_model = VGGFace(include_top = False, input_shape = image_shape, pooling='avg')
|
13 |
+
|
14 |
+
# Freeze all the layers till unfreeze layers
|
15 |
+
for layer in vgg_base_model.layers[:unfreeze_layers]:
|
16 |
+
layer.trainable = True
|
17 |
+
|
18 |
+
# for layer in vgg_base_model.layers[unfreeze_layers:]:
|
19 |
+
# layer.trainable = True
|
20 |
+
|
21 |
+
x = vgg_base_model(input_layer)
|
22 |
+
|
23 |
+
x = Dropout(drop_rate)(x)
|
24 |
+
output = Dense(num_classes, activation='softmax')(x)
|
25 |
+
|
26 |
+
model = Model(inputs=[input_layer], outputs=[output], name="Expression_Classifier")
|
27 |
+
model.load_weights(model_weights)
|
28 |
+
return model
|
29 |
+
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
model_path = "vgg_face_weights2.h5"
|
33 |
+
model = get_model(
|
34 |
+
image_shape = (224, 224, 3),
|
35 |
+
num_classes = 6,
|
36 |
+
model_weights = model_path
|
37 |
+
)
|
38 |
+
|
39 |
print(model.summary())
|