-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
70 lines (57 loc) · 3.18 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
from keras import layers, regularizers
from keras.models import Sequential
def create_model(data):
if data=="cifar10":
model = Sequential()
model.add(layers.Conv2D(32, (3,3), padding='same', activation='relu', input_shape=(32,32,3)))
model.add(layers.GroupNormalization())
model.add(layers.Conv2D(32, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization())
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.3))
model.add(layers.Conv2D(64, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization())
model.add(layers.Conv2D(64, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization())
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.5))
model.add(layers.Conv2D(128, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization())
model.add(layers.Conv2D(128, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization())
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.5))
model.add(layers.Flatten())
model.add(layers.Dense(128, activation='relu'))
model.add(layers.GroupNormalization())
model.add(layers.Dropout(0.5))
model.add(layers.Dense(10, activation='softmax', kernel_regularizer = regularizers.l2(0.0005)))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model
if data=="emnist" or data =="femnist":
model = Sequential()
model.add(layers.Conv2D(28, (3,3), padding='same', activation='relu', input_shape=(28,28, 1)))
model.add(layers.GroupNormalization(28))
model.add(layers.Conv2D(28, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization(28))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.3))
model.add(layers.Conv2D(56, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization(28))
model.add(layers.Conv2D(56, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization(28))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.5))
model.add(layers.Conv2D(112, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization(28))
model.add(layers.Conv2D(112, (3,3), padding='same', activation='relu'))
model.add(layers.GroupNormalization(28))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.5))
model.add(layers.Flatten())
model.add(layers.Dense(112, activation='relu'))
model.add(layers.GroupNormalization(28))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(62, activation='softmax', kernel_regularizer = regularizers.l2(0.0005)))
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
return model