-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.py
34 lines (22 loc) · 849 Bytes
/
logger.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
import tensorflow as tf
import numpy as np
class Logger(object):
def __init__(self, log_dir):
self.writer = tf.summary.FileWriter(log_dir)
def scalar_summary(self, tag, value, step):
summary = tf.Summary(
value=[tf.Summary.Value(tag=tag, simple_value=value)])
self.writter.add_summary(summary, step)
def image_summary(self, name, x, step):
x = x.numpy()[0,:,:,:]
x = np.moveaxis(x,0,-1)
x = np.expand_dims(x,0)
tensor = tf.convert_to_tensor(
x,
dtype=tf.floadt32,
name=None,
preferred_dtype=None
)
print(tensor.value)
summary = tf.summary.image(name=name, tensor=tensor)
self.writer.add_summary(summary, step).eval()