MCPcopy
hub / github.com/dbolya/yolact / MovingAverage

Class MovingAverage

utils/functions.py:9–48  ·  view source on GitHub ↗

Keeps an average window of the specified number of items.

Source from the content-addressed store, hash-verified

7from layers.interpolate import InterpolateModule
8
9class MovingAverage():
10 """ Keeps an average window of the specified number of items. """
11
12 def __init__(self, max_window_size=1000):
13 self.max_window_size = max_window_size
14 self.reset()
15
16 def add(self, elem):
17 """ Adds an element to the window, removing the earliest element if necessary. """
18 if not math.isfinite(elem):
19 print('Warning: Moving average ignored a value of %f' % elem)
20 return
21
22 self.window.append(elem)
23 self.sum += elem
24
25 if len(self.window) > self.max_window_size:
26 self.sum -= self.window.popleft()
27
28 def append(self, elem):
29 """ Same as add just more pythonic. """
30 self.add(elem)
31
32 def reset(self):
33 """ Resets the MovingAverage to its initial state. """
34 self.window = deque()
35 self.sum = 0
36
37 def get_avg(self):
38 """ Returns the average of the elements in the window. """
39 return self.sum / max(len(self.window), 1)
40
41 def __str__(self):
42 return str(self.get_avg())
43
44 def __repr__(self):
45 return repr(self.get_avg())
46
47 def __len__(self):
48 return len(self.window)
49
50
51class ProgressBar():

Callers 7

evalvideoFunction · 0.90
play_videoFunction · 0.90
evaluateFunction · 0.90
trainFunction · 0.90
yolact.pyFile · 0.90
smootherFunction · 0.90
plotMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected