| import json | |
| from pathlib import Path | |
| CAPTIONS_DIR = Path("/nobackup/zy_zhang/data/r1lite-20260423-lerobot/captions") | |
| NEW_CAPTION = "coffee making" | |
| files = sorted(CAPTIONS_DIR.glob("*.json")) | |
| print(f"Found {len(files)} json files") | |
| total_replaced = 0 | |
| for fp in files: | |
| with fp.open("r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| replaced = 0 | |
| for entry in data: | |
| if "caption" in entry and (entry["caption"] is None or entry["caption"] == "None"): | |
| entry["caption"] = NEW_CAPTION | |
| replaced += 1 | |
| if replaced: | |
| with fp.open("w", encoding="utf-8") as f: | |
| json.dump(data, f, indent=2, ensure_ascii=False) | |
| total_replaced += replaced | |
| print(f"{fp.name}: replaced {replaced} captions") | |
| print(f"\nDone. Total captions replaced: {total_replaced}") | |