-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
47 lines (41 loc) · 1.01 KB
/
utils.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
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
plt.switch_backend('agg')
def denormalize(img):
img = (img + 1) * 127.5
return img.astype(np.uint8)
def normalize(img):
return (img - 127.5) / 127.5
def visualize_rgb(img):
"""
Visualize a rgb image
:param img: RGB image
"""
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.imshow(img)
ax.axis("off")
ax.set_title("Image")
plt.show()
def save_rgb_img(img, path):
"""
Save a rgb image
"""
fig, ax = plt.subplots(1,1)
ax.imshow(img)
ax.axis("off")
ax.set_title("RGB Image")
plt.savefig(path)
plt.close()
def write_log(callback, name, loss, batch_no):
"""
Write training summary to TensorBoard
"""
# for name, value in zip(names, logs):
summary = tf.Summary()
summary_value = summary.value.add()
summary_value.simple_value = loss
summary_value.tag = name
callback.writer.add_summary(summary, batch_no)
callback.writer.flush()