def image(self, tag, image, step):
        image = np.asarray(image)
        if image.ndim == 2:
            image = image[:, :, None]
        if image.shape[-1] == 1:
            image = np.repeat(image, 3, axis=-1)

        bytesio = io.BytesIO()
        PIL.Image.fromarray(image).save(bytesio, 'PNG')
        image_summary = Summary.Image(encoded_image_string=bytesio.getvalue(),
                                      colorspace=3,
                                      height=image.shape[0],
                                      width=image.shape[1])
        self._write_event(Summary.Value(tag=tag, image=image_summary), step)
 def scalar(self, tag, value, step):
     self._write_event(Summary.Value(tag=tag, simple_value=float(value)),
                       step)
 def _write_event(self, summary_value, step):
     self.writer.add_event(
         Event(wall_time=round(time.time()),
               step=step,
               summary=Summary(value=[summary_value])))