Beispiel #1
0
def log_video(module, name, video_frames: List[np.ndarray]):
    # create video temp file
    fd, path = tempfile.mkstemp(suffix=".gif")
    os.close(fd)
    try:
        create_video(
            video_frames,
            os.path.dirname(path),
            os.path.basename(os.path.splitext(path)[0]),
            extension=".gif",
        )
    except Exception as e:
        print(e)
        os.remove(path)
        return

    size = os.path.getsize(path)
    while True:
        time.sleep(1)
        new_size = os.path.getsize(path)
        if size != 0 and new_size == size:
            break
        size = new_size

    for logger in get_loggers_as_list(module):
        if hasattr(logger, "log_artifact") and callable(logger.log_artifact):
            logger.log_artifact(path, name + ".gif")
    if os.path.exists(path):
        os.remove(path)
Beispiel #2
0
def log_video(module, name, video_frames: List[np.ndarray]):
    # create video temp file
    _fd, path = tempfile.mkstemp(suffix=".gif")
    try:
        create_video(video_frames, os.path.dirname(path),
                     os.path.basename(path))
    except Exception as e:
        print(e)
        os.remove(path)
        return

    for logger in get_loggers_as_list(module):
        if hasattr(logger, "log_artifact") and callable(logger.log_artifact):
            logger.log_artifact(path, name + ".gif")
    if os.path.exists(path):
        os.remove(path)
Beispiel #3
0
def test_create_video_float(images_f, tmpdir):
    tmp_dir = str(tmpdir.make_numbered_dir())
    create_video(images_f, tmp_dir, "vid", extension=".gif")
    assert os.path.exists(join(tmp_dir, "vid.gif"))
    create_video(images_f, tmp_dir, "vid", extension=".mp4")
    assert os.path.exists(join(tmp_dir, "vid.mp4"))