File size: 1,135 Bytes
a85377e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
071870f
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
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

import keras
from keras.layers import Input, Dropout, Dense
from keras.models import Model
from keras_vggface.vggface import VGGFace

def get_model(image_shape, num_classes, model_weights, unfreeze_layers=-3, drop_rate=0.5):
    
    input_layer = Input(shape=image_shape)
    vgg_base_model = VGGFace(include_top = False, input_shape = image_shape, pooling='avg')
    
    # Freeze all the layers till unfreeze layers
    for layer in vgg_base_model.layers[:unfreeze_layers]:
        layer.trainable = True
    
    # for layer in vgg_base_model.layers[unfreeze_layers:]:
    #     layer.trainable = True
    
    x = vgg_base_model(input_layer)
    
    x = Dropout(drop_rate)(x)
    output = Dense(num_classes, activation='softmax')(x)
    
    model = Model(inputs=[input_layer], outputs=[output], name="Expression_Classifier")
    model.load_weights(model_weights)
    return model


if __name__ == "__main__":
	model_path = "vgg_face_weights2.h5"
	model = get_model(
			image_shape = (224, 224, 3),
			num_classes = 6,
			model_weights = model_path
		)

	print(model.summary())