Download eval/source/robot_tools/trex/scripts/make_failure_examples.py from JiayiWuLeo/RobotZero: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/datasets/JiayiWuLeo/RobotZero/resolve/main/eval/source/robot_tools/trex/scripts/make_failure_examples.py
- Command line
-
hf download hf://datasets/JiayiWuLeo/RobotZero/eval/source/robot_tools/trex/scripts/make_failure_examples.py
-
curl -L -o make_failure_examples.py https://huggingface.co/datasets/JiayiWuLeo/RobotZero/resolve/main/eval/source/robot_tools/trex/scripts/make_failure_examples.py
1.8 kB
| import csv, json, os, shutil, sys | |
| sys.path.insert(0, "/home/wujiayir/robot_tools/trex/scripts"); sys.path.insert(0, "/home/wujiayir/robot_tools/droid/scripts") | |
| os.chdir("/home/wujiayir/robot_tools/trex") | |
| from trex_data import TrexDataset | |
| from render_episode import VideoWriter | |
| rows = [r for r in csv.DictReader(open("out/label/pilot_results.csv")) if r["label"] == "failure"] | |
| rows.sort(key=lambda r: -float(r["confidence"])) | |
| seen, picks = set(), [] | |
| for r in rows: | |
| mp = r["motor_primitive"] | |
| if mp in seen or mp in ("cut", "shake", "extract"): | |
| continue | |
| seen.add(mp); picks.append(r) | |
| if len(picks) == 8: | |
| break | |
| ds = TrexDataset("/home/wujiayir/public_datasets/trex") | |
| for r in picks: | |
| ep = int(r["episode_index"]); d = f"out/label/examples/{ep:05d}"; os.makedirs(d, exist_ok=True) | |
| w = VideoWriter(f"{d}/real_head_left.mp4", fps=30); n = 0 | |
| for item in ds.iter_frames(ep, "head_left"): | |
| f = item[-1] if isinstance(item, (tuple, list)) else item | |
| w.write(f); n += 1 | |
| w.release() | |
| for name in ["overlay", "render", "mask", "normal"]: | |
| src = f"out/{ep:05d}/head_left/{name}.mp4" | |
| if os.path.exists(src): | |
| shutil.copy(src, f"{d}/{name}.mp4") | |
| for s in "AB": | |
| shutil.copy(f"out/label/sheets/{ep:05d}_{s}.jpg", f"{d}/judge_sheet_{s}.jpg") | |
| shutil.copy(f"out/label/results/{ep:05d}.json", f"{d}/judge.json") | |
| keys = ("episode_index", "motor_primitive", "object", "target", "length", "task", "label", "confidence", "issues", "evidence_frame", "reason") | |
| json.dump({k: r[k] for k in keys}, open(f"{d}/info.json", "w"), indent=1, ensure_ascii=False) | |
| print("%05d | %-16s conf %.2f frames %d | %s | %s" % (ep, r["motor_primitive"], float(r["confidence"]), n, r["task"][:70], r["reason"][:110])) | |
| print("DONE") | |