Spaces:
Running
Running
Download train/make_dataset.py from VectorW/xlerobot-sim: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/spaces/VectorW/xlerobot-sim/resolve/main/train/make_dataset.py
- Command line
-
hf download hf://spaces/VectorW/xlerobot-sim/train/make_dataset.py
-
curl -L -o make_dataset.py https://huggingface.co/spaces/VectorW/xlerobot-sim/resolve/main/train/make_dataset.py
2.12 kB
| """Turn the pick demonstrations from tools/gen_demos.mjs into a LeRobot dataset (no images). | |
| usage: | |
| python train/make_dataset.py demos/pick_tabletop.jsonl data/xlerobot_sim_pick [--repo-id local/xlerobot_sim_pick] | |
| """ | |
| import argparse | |
| import json | |
| import shutil | |
| from pathlib import Path | |
| import numpy as np | |
| from lerobot.datasets.lerobot_dataset import LeRobotDataset | |
| TASK = "Pick up the object from the table." | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) | |
| parser.add_argument("demos", type=Path) | |
| parser.add_argument("root", type=Path) | |
| parser.add_argument("--repo-id", default="local/xlerobot_sim_pick") | |
| args = parser.parse_args() | |
| spec = json.loads(args.demos.with_suffix("").with_suffix(".features.json").read_text()) | |
| names = spec["features"] | |
| features = { | |
| "observation.state": {"dtype": "float32", "shape": (len(names["state"]),), "names": names["state"]}, | |
| "observation.environment_state": {"dtype": "float32", "shape": (len(names["environment"]),), "names": names["environment"]}, | |
| "action": {"dtype": "float32", "shape": (len(names["action"]),), "names": names["action"]}, | |
| } | |
| if args.root.exists(): | |
| shutil.rmtree(args.root) | |
| dataset = LeRobotDataset.create(args.repo_id, fps=spec["fps"], features=features, root=args.root, robot_type="xlerobot", use_videos=False) | |
| episodes = 0 | |
| with args.demos.open() as f: | |
| for line in f: | |
| ep = json.loads(line) | |
| for s, e, a in zip(ep["state"], ep["environment"], ep["action"]): | |
| dataset.add_frame({ | |
| "observation.state": np.asarray(s, dtype=np.float32), | |
| "observation.environment_state": np.asarray(e, dtype=np.float32), | |
| "action": np.asarray(a, dtype=np.float32), | |
| "task": TASK, | |
| }) | |
| dataset.save_episode() | |
| episodes += 1 | |
| dataset.finalize() | |
| print(f"{episodes} episodes, {dataset.meta.total_frames} frames at {spec['fps']} fps in {args.root}") | |
| if __name__ == "__main__": | |
| main() | |