summaryrefslogtreecommitdiff
path: root/src/training/trainer/util.py
diff options
context:
space:
mode:
authoraktersnurra <gustaf.rydholm@gmail.com>2020-08-20 22:18:35 +0200
committeraktersnurra <gustaf.rydholm@gmail.com>2020-08-20 22:18:35 +0200
commit1f459ba19422593de325983040e176f97cf4ffc0 (patch)
tree89fef442d5dbe0c83253e9566d1762f0704f64e2 /src/training/trainer/util.py
parent95cbdf5bc1cc9639febda23c28d8f464c998b214 (diff)
A lot of stuff working :D. ResNet implemented!
Diffstat (limited to 'src/training/trainer/util.py')
-rw-r--r--src/training/trainer/util.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/training/trainer/util.py b/src/training/trainer/util.py
new file mode 100644
index 0000000..132b2dc
--- /dev/null
+++ b/src/training/trainer/util.py
@@ -0,0 +1,19 @@
+"""Utility functions for training neural networks."""
+
+
+class RunningAverage:
+ """Maintains a running average."""
+
+ def __init__(self) -> None:
+ """Initializes the parameters."""
+ self.steps = 0
+ self.total = 0
+
+ def update(self, val: float) -> None:
+ """Updates the parameters."""
+ self.total += val
+ self.steps += 1
+
+ def __call__(self) -> float:
+ """Computes the running average."""
+ return self.total / float(self.steps)