forked from soprof/face-identification-tpe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnn.py
59 lines (45 loc) · 1.89 KB
/
cnn.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
from keras.layers import Flatten, Dense, Dropout
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.layers.advanced_activations import PReLU
from keras.models import Sequential
def build_cnn(dim, n_classes):
model = Sequential()
model.add(Convolution2D(96, 11, 11,
subsample=(4, 4),
input_shape=(dim, dim, 3),
init='glorot_uniform',
border_mode='same'))
model.add(PReLU())
model.add(MaxPooling2D((3, 3), strides=(2, 2)))
model.add(Convolution2D(256, 5, 5,
subsample=(1, 1),
init='glorot_uniform',
border_mode='same'))
model.add(PReLU())
model.add(MaxPooling2D((3, 3), strides=(2, 2)))
model.add(Convolution2D(384, 3, 3,
subsample=(1, 1),
init='glorot_uniform',
border_mode='same'))
model.add(PReLU())
model.add(Convolution2D(384, 3, 3,
subsample=(1, 1),
init='glorot_uniform',
border_mode='same'))
model.add(PReLU())
model.add(Convolution2D(256, 3, 3,
subsample=(1, 1),
init='glorot_uniform',
border_mode='same'))
model.add(PReLU())
model.add(MaxPooling2D((3, 3), strides=(2, 2)))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(2048, init='glorot_uniform'))
model.add(PReLU())
model.add(Dropout(0.5))
model.add(Dense(256, init='glorot_uniform'))
model.add(PReLU())
model.add(Dense(n_classes, init='glorot_uniform', activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
return model