-
Notifications
You must be signed in to change notification settings - Fork 5
/
model.py
99 lines (80 loc) · 3.4 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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.layers.core import Activation
from keras.layers.core import Dropout
from keras.layers.core import Dense
from keras.layers import Flatten
from keras.layers import Input
from keras.models import Model
class SVHNNet:
@staticmethod
def build(width, height, depth, classes):
inputShape = (height, width, depth)
inputs = Input(shape=inputShape)
# layer 1
x = Conv2D(filters=48, kernel_size=5, padding="same")(inputs)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=2, padding="same")(x)
x = Dropout(0.25)(x)
# layer 2
x = Conv2D(filters=64, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=1, padding="same")(x)
x = Dropout(0.25)(x)
# layer 3
x = Conv2D(filters=128, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=2, padding="same")(x)
x = Dropout(0.25)(x)
# layer 4
x = Conv2D(filters=160, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=1, padding="same")(x)
x = Dropout(0.25)(x)
# layer 5
x = Conv2D(filters=192, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=2, padding="same")(x)
x = Dropout(0.25)(x)
# layer 6
x = Conv2D(filters=192, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=1, padding="same")(x)
x = Dropout(0.25)(x)
# layer 7
x = Conv2D(filters=192, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=2, padding="same")(x)
x = Dropout(0.25)(x)
# layer 8
x = Conv2D(filters=192, kernel_size=5, padding="same")(x)
x = Activation("relu")(x)
x = BatchNormalization(axis=-1)(x)
x = MaxPooling2D(pool_size=2, strides=1, padding="same")(x)
x = Dropout(0.25)(x)
# layer 9
x = Flatten()(x)
x = Dense(units=3072)(x)
x = Activation("relu")(x)
x = Dropout(0.25)(x)
# layer 10
x = Dense(units=3072)(x)
x = Activation("relu")(x)
x = Dropout(0.25)(x)
# prediction layers
digit1 = Dense(classes, activation="softmax")(x)
digit2 = Dense(classes, activation="softmax")(x)
digit3 = Dense(classes, activation="softmax")(x)
digit4 = Dense(classes, activation="softmax")(x)
digit5 = Dense(classes, activation="softmax")(x)
seq_len = Dense(6, activation="softmax")(x)
model = Model(inputs=inputs, outputs=[digit1, digit2, digit3, digit4, digit5, seq_len])
return model