Example #1
0
def image(tag, tensor, rescale=1, dataformats="CHW"):
    """Outputs a `Summary` protocol buffer with images. The summary has up to
    `max_images` summary values containing images. The images are built from
    `tensor` which must be 3-D with shape `[height, width, channels]` and where
    `channels` can be:

    *  1: `tensor` is interpreted as Grayscale.
    *  3: `tensor` is interpreted as RGB.
    *  4: `tensor` is interpreted as RGBA.

    Args:
      tag: A name for the generated node. Will also serve as a series name in
        TensorBoard.
      tensor: A 3-D `uint8` or `float32` `Tensor` of shape `[height, width,
        channels]` where `channels` is 1, 3, or 4.
        'tensor' can either have values in [0, 1] (float32) or [0, 255] (uint8).
        The image() function will scale the image values to [0, 255] by applying
        a scale factor of either 1 (uint8) or 255 (float32).
    Returns:
      A scalar `Tensor` of type `string`. The serialized `Summary` protocol
      buffer.
    """
    tag = tbxsummary._clean_tag(tag)
    tensor = tbxmake_np(tensor)
    tensor = convert_to_HWC(tensor, dataformats)
    # Do not assume that user passes in values in [0, 255], use data type to detect
    if tensor.dtype != np.uint8:
        tensor = (tensor * 255.0).astype(np.uint8)

    image = tbxsummary.make_image(tensor, rescale=rescale)
    return TBXSummary(value=[TBXSummary.Value(tag=tag, image=image)])
Example #2
0
def add_video(writer,
              tag,
              tensor_thwc,
              global_step=None,
              fps=30,
              walltime=None):
    """found that add_video from tbX is buggy"""
    tag = _clean_tag(tag)
    video = make_video(tensor_thwc, fps)
    summary = Summary(value=[Summary.Value(tag=tag, image=video)])
    writer.file_writer.add_summary(summary, global_step, walltime)
Example #3
0
    def add_mpl_plot(self, tag, fig, global_step):
        if self.__show_mpl:
            import matplotlib.pyplot as plt
            plt.show()
        else:
            from PIL import Image
            import io
            fig.canvas.draw()

            pil_image = Image.frombytes('RGB', fig.canvas.get_width_height(),
                                        fig.canvas.tostring_rgb())

            output = io.BytesIO()
            pil_image.save(output, format='PNG')
            pil_image_string = output.getvalue()
            output.close()
            img_summary = Summary.Image(height=pil_image.height,
                                        width=pil_image.width,
                                        colorspace=3,
                                        encoded_image_string=pil_image_string)
            summary = Summary(
                value=[Summary.Value(tag=_clean_tag(tag), image=img_summary)])
            self.file_writer.add_summary(summary, global_step=global_step)
Example #4
0
 def _video(self, tag, vid):
     tag = tbxsummary._clean_tag(tag)
     return TBXSummary(value=[TBXSummary.Value(tag=tag, image=vid)])
Example #5
0
 def _video(tag, vid):
     # noinspection PyProtectedMember
     tag = tbxsummary._clean_tag(tag)
     return TBXSummary(value=[TBXSummary.Value(tag=tag, image=vid)])
Example #6
0
def histogram(name, values, bins, collections=None):
    name = _clean_tag(name)
    values = make_np(values)
    hist = make_histogram(values.astype(float), bins)
    return Summary(value=[Summary.Value(tag=name, histo=hist)])
Example #7
0
def counter(name, counter_dict):
    name = _clean_tag(name)
    hist = make_histogram_from_counter(counter_dict)
    return Summary(value=[Summary.Value(tag=name, histo=hist)])
Example #8
0
 def _to_image_summary_safe(tag, tensor):
     tag = _clean_tag(tag)
     img = make_image_summary(to_image(tensor))
     return Summary(value=[Summary.Value(tag=tag, image=img)])