#!/usr/bin/env python3 """Check the three source RLDS datasets before encoder training.""" from pathlib import Path import tensorflow as tf import tensorflow_datasets as tfds from openx.data.datasets.robomimic import mimicgen_transfer_dataset_transform from openx.data.utils import StateEncoding TASKS = {"coffee_preparation_d0": 0, "pick_place_d0": 4, "kitchen_d0": 9} def main(): root = Path("/workspace/single_task_transfer/data/rlds/mimic_gen_transfer") for name, task_id in TASKS.items(): builder = tfds.builder_from_directory(str(root / name / "1.0.0")) assert builder.info.splits["train"].num_examples == 100 episode = next(iter(builder.as_dataset(split="train").take(1))) steps = next(iter(episode["steps"].batch(10000).take(1))) length = int(tf.shape(steps["action"])[0]) assert tuple(steps["action"].shape[1:]) == (7,) assert tuple(steps["observation"]["agent_image"].shape[1:]) == (84, 84, 3) assert tuple(steps["observation"]["wrist_image"].shape[1:]) == (84, 84, 3) assert int(episode["episode_metadata"]["task_id"].numpy()) == task_id steps["episode_metadata"] = tf.nest.map_structure( lambda value: tf.repeat(value[None], length, axis=0), episode["episode_metadata"] ) standardized = mimicgen_transfer_dataset_transform(dict(steps)) assert standardized["observation"]["state"][StateEncoding.MISC].shape[-1] == 14 assert standardized["action"]["desired_delta"][StateEncoding.EE_POS].shape[-1] == 3 print(name, "episodes", 100, "first_episode_steps", length, "task_id", task_id) print("MULTI_SOURCE_RLDS_VERIFY_OK") if __name__ == "__main__": main()