Download chess-sim/code/sim/merge_datasets.py from Machanize/playful: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/datasets/Machanize/playful/resolve/main/chess-sim/code/sim/merge_datasets.py
- Command line
-
hf download hf://datasets/Machanize/playful/chess-sim/code/sim/merge_datasets.py
-
curl -L -o merge_datasets.py https://huggingface.co/datasets/Machanize/playful/resolve/main/chess-sim/code/sim/merge_datasets.py
2.06 kB
| """Merge phase 2 datasets generated separately (different seeds) into one. | |
| Uses LeRobot's aggregate_datasets, then joins the per-episode notes | |
| (phase2_episodes.jsonl, renumbered in merged order) and the generation summaries. | |
| Run: .venv/bin/python sim/merge_datasets.py data/so101_chess_sim_all data/so101_chess_sim data/so101_chess_sim_b | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| def main(): | |
| from lerobot.datasets.aggregate import aggregate_datasets | |
| from lerobot.datasets.lerobot_dataset import LeRobotDataset | |
| ap = argparse.ArgumentParser(description=__doc__) | |
| ap.add_argument("out") | |
| ap.add_argument("parts", nargs="+") | |
| args = ap.parse_args() | |
| parts = [Path(p) for p in args.parts] | |
| out = Path(args.out) | |
| aggregate_datasets(repo_ids=[f"local/part{i}" for i in range(len(parts))], aggr_repo_id="local/so101_chess_sim", | |
| roots=parts, aggr_root=out) | |
| offset, lines, summaries = 0, [], [] | |
| for p in parts: | |
| recs = [json.loads(line) for line in (p / "phase2_episodes.jsonl").read_text().splitlines()] | |
| for r in recs: | |
| r["part"] = p.name | |
| r["episode_index"] = offset + r["episode_index"] | |
| lines.append(json.dumps(r)) | |
| offset += len(recs) | |
| summaries.append(json.loads((p / "phase2_summary.json").read_text())) | |
| (out / "phase2_episodes.jsonl").write_text("\n".join(lines) + "\n") | |
| total = dict(episodes=sum(s["episodes"] for s in summaries), attempts=sum(s["attempts"] for s in summaries), | |
| minutes=round(sum(s["minutes"] for s in summaries), 1), parts=[p.name for p in parts], | |
| config=summaries[-1].get("config")) | |
| total["success_rate"] = round(total["episodes"] / total["attempts"], 4) | |
| (out / "phase2_summary.json").write_text(json.dumps(total, indent=2)) | |
| ds = LeRobotDataset("local/so101_chess_sim", root=out) | |
| print(f"{out}: {ds.num_episodes} episodes, {ds.num_frames} frames; notes {len(lines)}") | |
| if __name__ == "__main__": | |
| main() | |