-
Notifications
You must be signed in to change notification settings - Fork 270
/
memory_pressure.py
56 lines (43 loc) · 1.98 KB
/
memory_pressure.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
import talos
from talos.utils import SequenceGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten
from tensorflow.keras.layers import Conv2D
p = {'activation': ['relu'],
'optimizer': ['Adam'],
'losses': ['categorical_crossentropy'],
'dropout': [.2],
'batch_size': [256],
'epochs': [1, 1, 1, 1, 1]}
x_train, y_train, x_val, y_val = talos.templates.datasets.mnist()
@profile
def talos_version():
def mnist_model(x_train, y_train, x_val, y_val, params):
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation=params['activation'], input_shape=(28, 28, 1)))
model.add(Flatten())
model.add(Dense(128, activation=params['activation']))
model.add(Dropout(params['dropout']))
model.add(Dense(10, activation='softmax'))
model.compile(optimizer=params['optimizer'],
loss=params['losses'],
metrics=['acc', talos.utils.metrics.f1score])
out = model.fit_generator(SequenceGenerator(x_train,
y_train,
batch_size=params['batch_size']),
epochs=params['epochs'],
validation_data=[x_val, y_val],
callbacks=[],
workers=4,
verbose=0)
return out, model
scan_object = talos.Scan(x=x_train,
y=y_train,
x_val=x_val,
y_val=y_val,
params=p,
model=mnist_model,
experiment_name='mnist',
save_weights=False)
if __name__ == "__main__":
talos_version()