-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainer.py
36 lines (36 loc) · 898 Bytes
/
trainer.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
import tensorflow as tf
from tensorflow import keras
from model_example import make_model
model = make_model(input_shape=(80,60,1), num_classes=2)
epochs = 10
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
"data",
validation_split=0.3,
subset="training",
seed=1337,
image_size=(80,60),
color_mode="grayscale",
batch_size=8,
shuffle=True
)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
"data",
validation_split=0.3,
subset="validation",
seed=1337,
image_size=(80,60),
color_mode="grayscale",
batch_size=8,
shuffle=True
)
callbacks = [
keras.callbacks.ModelCheckpoint("save_at_{epoch}.h5"),
]
model.compile(
optimizer=keras.optimizers.Adam(0.001),
loss="binary_crossentropy",
metrics=["accuracy"],
)
model.fit(
train_ds, epochs=epochs, callbacks=callbacks, validation_data=val_ds,
)