-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_ascent.py
75 lines (61 loc) · 3.43 KB
/
model_ascent.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
from keras import layers, regularizers
from keras.models import Sequential
import keras.backend as kb
def custom_loss(y_actual,y_pred):
custom_loss=kb.square(y_actual-y_pred)
return custom_loss*(-1)
def create_model_ascent(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=custom_loss, metrics=['accuracy'])
return model
if data=="emnist":
model = Sequential()
model.add(layers.Conv2D(28, (3,3), padding='same', activation='relu', input_shape=(28,28,1)))
model.add(layers.BatchNormalization(scale=False, center=False))
model.add(layers.Conv2D(28, (3,3), padding='same', activation='relu'))
model.add(layers.BatchNormalization(scale=False, center=False))
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.BatchNormalization(scale=False, center=False))
model.add(layers.Conv2D(56, (3,3), padding='same', activation='relu'))
model.add(layers.BatchNormalization(scale=False, center=False))
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.BatchNormalization(scale=False, center=False))
model.add(layers.Conv2D(112, (3,3), padding='same', activation='relu'))
model.add(layers.BatchNormalization(scale=False, center=False))
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.BatchNormalization(scale=False, center=False))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(47, activation='softmax', kernel_regularizer = regularizers.l2(0.0005)))
model.compile(optimizer='adam', loss=custom_loss, metrics=['accuracy'])
return model