-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdataset_render.py
51 lines (37 loc) · 1.51 KB
/
dataset_render.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from absl import app, flags
from src import d4rl_utils
import d4rl
import numpy as np
import tqdm
FLAGS = flags.FLAGS
flags.DEFINE_string('env_name', 'kitchen-mixed-v0', '')
def kitchen_render(kitchen_env, wh=64):
from dm_control.mujoco import engine
camera = engine.MovableCamera(kitchen_env.sim, wh, wh)
camera.set_pose(distance=1.86, lookat=[-0.3, .5, 2.], azimuth=90, elevation=-60)
img = camera.render()
return img
def main(_):
if 'kitchen' in FLAGS.env_name:
env = d4rl_utils.make_env(FLAGS.env_name)
dataset = d4rl.qlearning_dataset(env)
env.reset()
pixel_dataset = dataset.copy()
pixel_obs = []
pixel_next_obs = []
for i in tqdm.tqdm(range(len(dataset['observations']))):
ob = dataset['observations'][i]
next_ob = dataset['next_observations'][i]
env.sim.set_state(np.concatenate([ob[:30], np.zeros(29)]))
env.sim.forward()
pixel_ob = kitchen_render(env, wh=64)
env.sim.set_state(np.concatenate([next_ob[:30], np.zeros(29)]))
env.sim.forward()
pixel_next_ob = kitchen_render(env, wh=64)
pixel_obs.append(pixel_ob)
pixel_next_obs.append(pixel_next_ob)
pixel_dataset['observations'] = np.array(pixel_obs)
pixel_dataset['next_observations'] = np.array(pixel_next_obs)
np.savez_compressed(f'data/d4rl_kitchen_rendered/{FLAGS.env_name}.npz', **pixel_dataset)
if __name__ == '__main__':
app.run(main)