File size: 825 Bytes
d821aa4 | 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 | 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}")
|