Пример #1
0
def render(env_name):
    from many_world import IS_PATCHED
    assert IS_PATCHED, "need the patched gym"
    import gym, numpy as np
    from tqdm import tqdm
    from ml_logger import logger

    logger.prefix = env_name

    env = gym.make(env_name)
    env.reset()

    frames = []

    y = 0
    args = [
        dict(x=x, y=y, filename=f"images/{x:0.3f},{y:0.3f}.png")
        for x in np.linspace(-0.25, 0.25, 128)
    ]
    logger.log_data(args, 'index.pkl')

    for p in tqdm(args):
        x, y, filename = p['x'], p['y'], p['filename']
        env.set_state(np.array([x, y, 0, 0]), np.array([0, 0, 0, 0]))
        # env.do_simulation([0, 0], 1) # PointMass does not need this.
        image = env.render('grey', width=20, height=20)
        frames.append(image)
        logger.log_image(image, filename)

    print('saving video')
    logger.log_video(frames, f"{env_name}.mp4")
    print('done')
Пример #2
0
def test_video(setup):
    import numpy as np

    def im(x, y):
        canvas = np.zeros((200, 200))
        for i in range(200):
            for j in range(200):
                if x - 5 < i < x + 5 and y - 5 < j < y + 5:
                    canvas[i, j] = 1
        return canvas

    frames = [im(100 + i, 80) for i in range(20)]

    logger.log_video(frames, "test_video.mp4")
Пример #3
0
def test_video(setup):
    import numpy as np

    def im(x, y):
        canvas = np.ones((640, 480), dtype=np.float32) * 0.001
        for i in range(200):
            for j in range(200):
                if x - 5 < i < x + 5 and y - 5 < j < y + 5:
                    canvas[i, j] = 1
        return canvas

    frames = [im(100 + i, 80) for i in range(20)]

    logger.log_video(frames, "test_video.mp4")
def main(env_id="Reacher-v2"):
    # env_name = "PointMass-v0"
    samples = dynamics_data_gen(env_name=env_id,
                                start_seed=0,
                                timesteps=50,
                                n_parallel_envs=5,
                                width=28,
                                height=28)

    for k, v in samples.items():
        print(k, v.shape)

    video = np.swapaxes(samples['views'], 0, 1).reshape(-1, 28, 28, 3)
    from ml_logger import logger
    logger.log_video(video, 'test.mp4')