-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
37 lines (30 loc) · 1.01 KB
/
log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Keeps logs on metrics/losses, and it time stamps them.
# This is mainly used to keep track the previously logged metrics/losesses which
# is used to determine the best model to save
import time
class LogMetric:
"""Mainly used to log previously made metrics & lossess and timestamps them - used for determing best model to save"""
def __init__(self):
self.metric = 0.0
self.loss = 0.0
self.time = 0.0
def reset(self):
self.metric = 0.0
self.loss = 0.0
self.time = 0.0
def update(self, metric, loss):
self.metric = metric
self.loss = loss
self.time = time.strftime("%Y%m%d_%H%M%S")
def update_tuple(self, metric, loss):
if isinstance(metric, tuple) is False:
raise RuntimeError("When using `update_tuple()`, please use a tuple for `metric`!")
self.metric = metric
self.loss = loss
self.time = time.strftime("%Y%m%d_%H%M%S")
def getTime(self):
return self.time
def getMetric(self):
return self.metric
def getLoss(self):
return self.loss