-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotter.py
More file actions
30 lines (21 loc) · 787 Bytes
/
Plotter.py
File metadata and controls
30 lines (21 loc) · 787 Bytes
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
import matplotlib.pyplot as plt
from queue import Queue
class Plotter():
def __init__(self, mode='train'):
if mode not in ('train', 'test'):
raise ValueError("Please specify a valid plotting mode")
self.mode = mode
self.gen_loss = []
self.i = 0
def add_loss(self, gen_loss):
self.i += 1
self.gen_loss.append(gen_loss)
self.gen_loss = self.gen_loss[-1000:]
if self.i%50 == 0:
self.save_graph()
def save_graph(self):
x = range(1, len(self.gen_loss) + 1)
plt.plot(x, self.gen_loss, 'r-', label='Generator')
plt.xlabel('iterations')
plt.ylabel('loss')
plt.savefig("losses_train.png" if self.mode == 'train' else 'losses_test.png')