Created
August 19, 2020 09:14
-
-
Save peakBreaker/725faf35fb063d08c80495059187c251 to your computer and use it in GitHub Desktop.
Using tensorflow keras callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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