-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor.py
65 lines (54 loc) · 1.57 KB
/
monitor.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import matplotlib.pyplot as plt
import numpy as np
def plot_losses(d_loss_log_real, d_loss_log_fake, g_loss_log_adv):
print("Plotting Discriminator and Generator Loss Logs")
plt.plot(
d_loss_log_real[:, 0],
d_loss_log_real[:, 1],
label="Discriminator Loss - Real",
)
plt.plot(
d_loss_log_fake[:, 0],
d_loss_log_fake[:, 1],
label="Discriminator Loss - Fake",
)
plt.plot(g_loss_log_adv[:, 0], g_loss_log_adv[:, 1], label="Generator Loss")
plt.xlabel("Epochs")
plt.ylabel("Loss")
plt.legend()
plt.title("DCGAN")
plt.grid(True)
plt.show()
def preview_dataset(data: list):
"""
Preview dataset images
:param data: Given training set
"""
print(f"Cataract Image Set")
_, ax = plt.subplots(5, 5, figsize=(15, 15))
for i, data in enumerate(data[:25]):
img_data = data[0]
ax[i // 5, i % 5].imshow(img_data)
ax[i // 5, i % 5].axis("off")
plt.show()
def monitor_generated_samples(
samples_num: int,
img_shape: tuple,
samples_dir: str,
gen_imgs: np.array,
epoch_num: int,
):
"""
Show & Save Generated Samples
:param epoch: Amount of epochs. Used to save in filename for the generated sample.
"""
x_fake = gen_imgs
for k in range(samples_num):
plt.subplot(2, 5, k + 1)
plt.imshow(np.uint8(255 * (x_fake[k].reshape(img_shape))))
plt.savefig(os.path.join(samples_dir, f"{epoch_num}_samples.png"))
plt.xticks([])
plt.yticks([])
plt.tight_layout()
plt.show()