forked from 0xTechSavvy/autoaugment
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mychild.py
36 lines (31 loc) · 1.21 KB
/
mychild.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
from keras import models, layers, optimizers
class Child:
# architecture from: https://github.com/keras-team/keras/blob/master/examples/mnist_cnn.py
def __init__(self, model, batch_size, epochs):
self.model = model
self.batch_size = batch_size
self.epochs = epochs
def fit(self, gen, nbatches, val_X, val_Y):
history = self.model.fit_generator(
gen, nbatches, self.epochs,
verbose=2,
use_multiprocessing=True,
validation_data=[val_X, val_Y]
)
return history
def evaluate(self, X, y):
return self.model.evaluate(X, y, verbose=2)[1]
def create_simple_conv(input_shape):
x = input_layer = layers.Input(shape=input_shape)
x = layers.Conv2D(32, 3, activation='relu')(x)
x = layers.Conv2D(64, 3, activation='relu')(x)
x = layers.MaxPooling2D(2)(x)
x = layers.Dropout(0.25)(x)
x = layers.Flatten()(x)
x = layers.Dense(128, activation='relu')(x)
x = layers.Dropout(0.5)(x)
x = layers.Dense(10, activation='softmax')(x)
model = models.Model(input_layer, x)
optimizer = optimizers.SGD(decay=1e-4)
model.compile(optimizer, 'categorical_crossentropy', ['accuracy'])
return model