From 658f4ddfeb0b3e7e237341bb1fe6d6b55172a833 Mon Sep 17 00:00:00 2001
From: Felix Kleinert <f.kleinert@fz-juelich.de>
Date: Mon, 5 Jul 2021 07:53:20 +0200
Subject: [PATCH] first draft of callback

---
 mlair/model_modules/keras_extensions.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/mlair/model_modules/keras_extensions.py b/mlair/model_modules/keras_extensions.py
index 33358e56..bc868765 100644
--- a/mlair/model_modules/keras_extensions.py
+++ b/mlair/model_modules/keras_extensions.py
@@ -8,6 +8,7 @@ import math
 import pickle
 from typing import Union, List
 from typing_extensions import TypedDict
+from time import time
 
 import numpy as np
 from keras import backend as K
@@ -111,6 +112,19 @@ class LearningRateDecay(History):
         return K.get_value(self.model.optimizer.lr)
 
 
+class TimingCallback(Callback):
+    def __init__(self):
+        self.logs = []
+        self.starttime = None
+        super().__init__()
+
+    def on_epoch_begin(self, logs={}):
+        self.starttime = time()
+
+    def on_epoch_end(self, logs={}):
+        self.logs.append(time()-self.starttime)
+
+
 class ModelCheckpointAdvanced(ModelCheckpoint):
     """
     Enhance the standard ModelCheckpoint class by additional saves of given callbacks.
-- 
GitLab