MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / TrainingStats

Class TrainingStats

tools/utils/stats.py:27–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26
27class TrainingStats(object):
28 def __init__(self, window_size, stats_keys):
29 self.window_size = window_size
30 self.smoothed_losses_and_metrics = {
31 key: SmoothedValue(window_size)
32 for key in stats_keys
33 }
34
35 def update(self, stats):
36 for k, v in stats.items():
37 if k not in self.smoothed_losses_and_metrics:
38 self.smoothed_losses_and_metrics[k] = SmoothedValue(
39 self.window_size)
40 self.smoothed_losses_and_metrics[k].add_value(v)
41
42 def get(self, extras=None):
43 stats = collections.OrderedDict()
44 if extras:
45 for k, v in extras.items():
46 stats[k] = v
47 for k, v in self.smoothed_losses_and_metrics.items():
48 stats[k] = round(v.get_median_value(), 6)
49
50 return stats
51
52 def log(self, extras=None):
53 d = self.get(extras)
54 strs = []
55 for k, v in d.items():
56 strs.append("{}: {:x<6f}".format(k, v))
57 strs = ", ".join(strs)
58 return strs

Callers 1

trainMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected