Jyothirmai commited on
Commit
74ff854
·
verified ·
1 Parent(s): 1162512

Delete logger.py

Browse files
Files changed (1) hide show
  1. logger.py +0 -71
logger.py DELETED
@@ -1,71 +0,0 @@
1
- # Code referenced from https://gist.github.com/gyglim/1f8dfb1b5c82627ae3efcfbbadb9f514
2
- import tensorflow as tf
3
- import numpy as np
4
- import scipy.misc
5
- try:
6
- from StringIO import StringIO # Python 2.7
7
- except ImportError:
8
- from io import BytesIO # Python 3.x
9
-
10
-
11
- class Logger(object):
12
-
13
- def __init__(self, log_dir):
14
- """Create a summary writer logging to log_dir."""
15
- self.writer = tf.summary.FileWriter(log_dir)
16
-
17
- def scalar_summary(self, tag, value, step):
18
- """Log a scalar variable."""
19
- summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value)])
20
- self.writer.add_summary(summary, step)
21
-
22
- def image_summary(self, tag, images, step):
23
- """Log a list of images."""
24
-
25
- img_summaries = []
26
- for i, img in enumerate(images):
27
- # Write the image to a string
28
- try:
29
- s = StringIO()
30
- except:
31
- s = BytesIO()
32
- scipy.misc.toimage(img).save(s, format="png")
33
-
34
- # Create an Image object
35
- img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
36
- height=img.shape[0],
37
- width=img.shape[1])
38
- # Create a Summary value
39
- img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_sum))
40
-
41
- # Create and write Summary
42
- summary = tf.Summary(value=img_summaries)
43
- self.writer.add_summary(summary, step)
44
-
45
- def histo_summary(self, tag, values, step, bins=1000):
46
- """Log a histogram of the tensor of values."""
47
-
48
- # Create a histogram using numpy
49
- counts, bin_edges = np.histogram(values, bins=bins)
50
-
51
- # Fill the fields of the histogram proto
52
- hist = tf.HistogramProto()
53
- hist.min = float(np.min(values))
54
- hist.max = float(np.max(values))
55
- hist.num = int(np.prod(values.shape))
56
- hist.sum = float(np.sum(values))
57
- hist.sum_squares = float(np.sum(values**2))
58
-
59
- # Drop the start of the first bin
60
- bin_edges = bin_edges[1:]
61
-
62
- # Add bin edges and counts
63
- for edge in bin_edges:
64
- hist.bucket_limit.append(edge)
65
- for c in counts:
66
- hist.bucket.append(c)
67
-
68
- # Create and write Summary
69
- summary = tf.Summary(value=[tf.Summary.Value(tag=tag, histo=hist)])
70
- self.writer.add_summary(summary, step)
71
- self.writer.flush()