MCPcopy Index your code
hub / github.com/openai/guided-diffusion / TensorBoardOutputFormat

Class TensorBoardOutputFormat

guided_diffusion/logger.py:150–188  ·  view source on GitHub ↗

Dumps key/value pairs into TensorBoard's numeric format.

Source from the content-addressed store, hash-verified

148
149
150class TensorBoardOutputFormat(KVWriter):
151 """
152 Dumps key/value pairs into TensorBoard's numeric format.
153 """
154
155 def __init__(self, dir):
156 os.makedirs(dir, exist_ok=True)
157 self.dir = dir
158 self.step = 1
159 prefix = "events"
160 path = osp.join(osp.abspath(dir), prefix)
161 import tensorflow as tf
162 from tensorflow.python import pywrap_tensorflow
163 from tensorflow.core.util import event_pb2
164 from tensorflow.python.util import compat
165
166 self.tf = tf
167 self.event_pb2 = event_pb2
168 self.pywrap_tensorflow = pywrap_tensorflow
169 self.writer = pywrap_tensorflow.EventsWriter(compat.as_bytes(path))
170
171 def writekvs(self, kvs):
172 def summary_val(k, v):
173 kwargs = {"tag": k, "simple_value": float(v)}
174 return self.tf.Summary.Value(**kwargs)
175
176 summary = self.tf.Summary(value=[summary_val(k, v) for k, v in kvs.items()])
177 event = self.event_pb2.Event(wall_time=time.time(), summary=summary)
178 event.step = (
179 self.step
180 ) # is there any reason why you'd want to specify the step?
181 self.writer.WriteEvent(event)
182 self.writer.Flush()
183 self.step += 1
184
185 def close(self):
186 if self.writer:
187 self.writer.Close()
188 self.writer = None
189
190
191def make_output_format(format, ev_dir, log_suffix=""):

Callers 1

make_output_formatFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected