diff --git a/modules/util/util.py b/modules/util/util.py
index ae662b083a83e3a8934f9a371e929f4dbd9c017f..e1dfd9cc21a155916fa40bdf09798afaa14cb537 100644
--- a/modules/util/util.py
+++ b/modules/util/util.py
@@ -16,6 +16,36 @@ class GenericException(Exception):
         self.message = message
 
 
+class EarlyStop:
+    def __init__(self, window_length=3, patience=5):
+        self.patience = patience
+        self.min = np.finfo(np.single)
+        self.cnt = 0
+        self.cnt_wait = 0
+        self.window = np.zeros(window_length, dtype=np.single)
+        self.window.fill(np.nan)
+
+    def check_stop(self, value):
+        self.window[:-1] = self.window[1:]
+        self.window[-1] = value
+
+        if np.any(np.isnan(self.window)):
+            return False
+
+        ave = np.mean(self.window)
+        if ave < self.min:
+            self.min = ave
+            self.cnt_wait = 0
+            return False
+        else:
+            self.cnt_wait += 1
+
+        if self.cnt_wait > self.patience:
+            return True
+        else:
+            return False
+
+
 def get_time_tuple_utc(timestamp):
     dt_obj = datetime.datetime.fromtimestamp(timestamp, timezone.utc)
     return dt_obj, dt_obj.timetuple()