Skip to content

Instantly share code, notes, and snippets.

@peakBreaker
Created August 19, 2020 09:14
Show Gist options
  • Save peakBreaker/725faf35fb063d08c80495059187c251 to your computer and use it in GitHub Desktop.
Save peakBreaker/725faf35fb063d08c80495059187c251 to your computer and use it in GitHub Desktop.
Using tensorflow keras callbacks
def train_model():
# ... Define the model and training data etc here
def my_callback(epoch, logs):
# Optionally clear the file if it exists here? or use on_train_begin cb
# Focus on the point here
with open('train_logs.json', 'a') as l:
data =json.dumps({'epoch': epoch, **logs})
l.write(data + '\n')
my_callbacks = [
tf.keras.callbacks.LambdaCallback(
on_epoch_end=my_callback
)
]
batch_size = 512
epochs = 10
model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, validation_split=0.1, callbacks=my_callbacks)
return model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment