Example #1
0
def clips_to_video(clips, h, w, c):
    # encode sequence of images into gif string
    clip = concatenate_videoclips(clips)

    filename = tempfile.NamedTemporaryFile(suffix=".gif", delete=False).name

    # moviepy >= 1.0.0 use logger=None to suppress output.
    try:
        clip.write_gif(filename, verbose=False, logger=None)
    except TypeError:
        get_logger().warning(
            "Upgrade to moviepy >= 1.0.0 to suppress the progress bar.")
        clip.write_gif(filename, verbose=False)

    with open(filename, "rb") as f:
        tensor_string = f.read()

    try:
        os.remove(filename)
    except OSError:
        get_logger().warning(
            "The temporary file used by moviepy cannot be deleted.")

    return TBXSummary.Image(height=h,
                            width=w,
                            colorspace=c,
                            encoded_image_string=tensor_string)
Example #2
0
def summary_image(img):
    output = io.BytesIO()
    img.save(output, format='PNG')
    encoded = output.getvalue()
    output.close()
    return Summary.Image(height=img.height,
                         width=img.width,
                         colorspace=len(img.getbands()),
                         encoded_image_string=encoded)
Example #3
0
def make_video(tensor, fps):
    t, h, w, c = tensor.shape
    with tempfile.NamedTemporaryFile() as f:
        filename = f.name + '.gif'
    images = [tensor[t] for t in range(tensor.shape[0])]
    imageio.mimwrite(filename, images, duration=0.04)
    with open(filename, 'rb') as f:
        tensor_string = f.read()
    try:
        os.remove(filename)
    except OSError:
        pass

    return Summary.Image(height=h,
                         width=w,
                         colorspace=c,
                         encoded_image_string=tensor_string)