Created
May 24, 2018 15:20
-
-
Save MaxHalford/e661602ae9e60fd04df94d6c15a303a3 to your computer and use it in GitHub Desktop.
Keras eval callback
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
import keras | |
class EvalCallback(keras.callbacks.Callback): | |
def __init__(self, X_val, y_val, metric): | |
super().__init__() | |
self.X_val = X_val | |
self.y_val = y_val | |
self.metric = metric | |
def on_epoch_end(self, epoch, logs={}): | |
y_pred = self.model.predict(self.X_val, verbose=0) | |
score = self.metric(self.y_val, y_pred) | |
print('\nEpoch {} score: {:.6f}\n'.format(epoch+1, score)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment