-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
67 lines (60 loc) · 2.32 KB
/
models.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
from keras.models import Sequential
from keras.layers import Flatten, Dense
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import Conv2D, MaxPooling2D
from keras.optimizers import Adam
from sklearn import metrics
#adam optimizer with learning rate .0001 and decay 5e-5
def standardCompiledSimpConvNN():
model = simpConvNN()
optimizer = Adam(lr = .0001, decay = 5e-5)
model.compile(optimizer=optimizer,
loss='binary_crossentropy',
metrics=['accuracy'])
return model
#Best performance with Adam, default learning rate, learning rate decay of 5e-6, 25 epochs
def simpConvNN(input_shape=(64, 64, 3)):
model = Sequential()
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), input_shape=input_shape))
#model went from 64x64x3 to 32x32x3
model.add(Conv2D(64, (3, 3), strides=(2,2), activation='softplus'))
#model is now 16x16x64
model.add(Conv2D(32, (3, 3), activation='softplus'))
#model is now 16x16x32
model.add(Conv2D(16, (3, 3), activation='softplus'))
#model is now 16x16x16
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
#model is now 8x8x16
model.add(Flatten())
#model is now 1024 (flattened from 8x8x16)
model.add(Dense(128, activation='softplus'))
model.add(Dense(32, activation='softplus'))
model.add(Dense(1, activation='sigmoid'))
return model
#adam optimizer with learning rate .000005 and decay 5e-5
def standardCompiledSimpConvNNBatchFirst():
model = simpConvNN()
optimizer = Adam(lr = .000005, decay = 5e-5)
model.compile(optimizer=optimizer,
loss='binary_crossentropy',
metrics=['accuracy'])
return model
def simpConvNNBatchFirst(input_shape=(64, 64, 3)):
model = Sequential()
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), input_shape=input_shape))
#model went from 64x64x3 to 32x32x3
model.add(Conv2D(64, (3, 3), strides=(2,2), activation='softplus'))
#model is now 16x16x64
model.add(Conv2D(32, (3, 3), activation='softplus'))
#model is now 16x16x32
model.add(Conv2D(16, (3, 3), activation='softplus'))
#model is now 16x16x16
model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2)))
#model is now 8x8x16
model.add(Flatten())
#model is now 1024 (flattened from 8x8x16)
model.add(Dense(128, activation='softplus'))
model.add(Dense(32, activation='softplus'))
model.add(Dense(1, activation='sigmoid'))
return model