Upload prep_lerobot.py with huggingface_hub
Browse files- prep_lerobot.py +48 -2
prep_lerobot.py
CHANGED
|
@@ -33,16 +33,59 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
| 33 |
import transform_batch as tb # noqa: E402 (reuse _episode_range/_ensure/REPO/PREFIX)
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def main():
|
| 37 |
ap = argparse.ArgumentParser()
|
| 38 |
ap.add_argument("--flat", required=True, help="/workspace/transform/retargeted")
|
| 39 |
ap.add_argument("--cache", required=True, help="/workspace/ego_cache")
|
| 40 |
ap.add_argument("--retgt-out", default="/workspace/retargeted")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
a = ap.parse_args()
|
| 42 |
|
| 43 |
cache = Path(a.cache)
|
| 44 |
ego_root = cache / tb.REPO.replace("/", "__") # to_lerobot EGO = this (<cat>/videos + meta)
|
| 45 |
-
done, vids, skipped = 0, 0, 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Pass 1 — resolve each retargeted clip to (cat, ep, chunk, file) and symlink it into the
|
| 48 |
# category layout. Cheap (local hdf5 attrs + cached meta parquets), so keep it sequential.
|
|
@@ -52,6 +95,9 @@ def main():
|
|
| 52 |
with h5py.File(hp, "r") as h:
|
| 53 |
cat = str(h.attrs["task"])
|
| 54 |
ep = int(str(h.attrs["clip"]).split("-")[1])
|
|
|
|
|
|
|
|
|
|
| 55 |
r = tb._episode_range(cache, cat, ep)
|
| 56 |
ci, fi = r["data/chunk_index"], r["data/file_index"]
|
| 57 |
fyy = f"file-{fi:03d}"
|
|
@@ -90,7 +136,7 @@ def main():
|
|
| 90 |
with ThreadPoolExecutor(max_workers=min(24, max(1, len(uniq)))) as ex:
|
| 91 |
vids = sum(1 for ok in ex.map(_dlvid, uniq) if ok)
|
| 92 |
|
| 93 |
-
print(json.dumps({"clips": done, "videos": vids, "skipped": skipped,
|
| 94 |
"retgt": a.retgt_out, "ego": str(ego_root)}))
|
| 95 |
|
| 96 |
|
|
|
|
| 33 |
import transform_batch as tb # noqa: E402 (reuse _episode_range/_ensure/REPO/PREFIX)
|
| 34 |
|
| 35 |
|
| 36 |
+
def _verdict(m: dict, th: dict) -> str:
|
| 37 |
+
"""Re-grade one clip's metrics with the user's thresholds (mirror of the console re-grade)."""
|
| 38 |
+
rank = {"PASS": 0, "WARN": 1, "FAIL": 2, "?": 0}
|
| 39 |
+
ik = max(float(m.get("ik_R_cm", 0) or 0), float(m.get("ik_L_cm", 0) or 0))
|
| 40 |
+
ori = max(float(m.get("ori_R_deg", 0) or 0), float(m.get("ori_L_deg", 0) or 0))
|
| 41 |
+
track = "FAIL" if ik >= th["ik_fail"] else "WARN" if ik >= th["ik_warn"] else "PASS"
|
| 42 |
+
ori_g = "FAIL" if ori >= th["ori_fail"] else "WARN" if ori >= th["ori_warn"] else "PASS"
|
| 43 |
+
arms = "PASS" if m.get("collision") == "clean" else {"allow": "PASS", "warn": "WARN", "fail": "FAIL"}.get(th["arms"], "PASS")
|
| 44 |
+
mraw = m.get("qa_motion") or m.get("qa") or "PASS"
|
| 45 |
+
arm_m = th["motion"]
|
| 46 |
+
motion = "PASS" if arm_m == "off" else ("FAIL" if (arm_m == "strict" and mraw in ("WARN", "FAIL")) else mraw)
|
| 47 |
+
return max([track, ori_g, arms, motion], key=lambda v: rank.get(v, 0))
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _excluded_ids(report_path: str, th: dict) -> set:
|
| 51 |
+
"""clip_ids ('<cat>#<ep>') the user's thresholds flag as FAIL — skipped from the dataset."""
|
| 52 |
+
try:
|
| 53 |
+
rep = json.loads(Path(report_path).read_text())
|
| 54 |
+
except Exception:
|
| 55 |
+
return set()
|
| 56 |
+
out = set()
|
| 57 |
+
for c in rep.get("clips", []):
|
| 58 |
+
if c.get("status") == "done" and _verdict(c.get("metrics") or {}, th) == "FAIL":
|
| 59 |
+
out.add(c.get("clip_id"))
|
| 60 |
+
return out
|
| 61 |
+
|
| 62 |
+
|
| 63 |
def main():
|
| 64 |
ap = argparse.ArgumentParser()
|
| 65 |
ap.add_argument("--flat", required=True, help="/workspace/transform/retargeted")
|
| 66 |
ap.add_argument("--cache", required=True, help="/workspace/ego_cache")
|
| 67 |
ap.add_argument("--retgt-out", default="/workspace/retargeted")
|
| 68 |
+
# Exclude-enforcement: if --exclude, drop clips the user's thresholds flag as FAIL (read from
|
| 69 |
+
# the retarget report). Off by default — we never auto-drop unless the user opts in.
|
| 70 |
+
ap.add_argument("--report", default="", help="/workspace/report.json (for --exclude)")
|
| 71 |
+
ap.add_argument("--exclude", type=int, default=0, help="1 = drop FAIL-flagged clips")
|
| 72 |
+
ap.add_argument("--ik-warn", type=float, default=3.0)
|
| 73 |
+
ap.add_argument("--ik-fail", type=float, default=6.0)
|
| 74 |
+
ap.add_argument("--ori-warn", type=float, default=15.0)
|
| 75 |
+
ap.add_argument("--ori-fail", type=float, default=30.0)
|
| 76 |
+
ap.add_argument("--arms", default="allow")
|
| 77 |
+
ap.add_argument("--motion", default="off")
|
| 78 |
a = ap.parse_args()
|
| 79 |
|
| 80 |
cache = Path(a.cache)
|
| 81 |
ego_root = cache / tb.REPO.replace("/", "__") # to_lerobot EGO = this (<cat>/videos + meta)
|
| 82 |
+
done, vids, skipped, excluded = 0, 0, 0, 0
|
| 83 |
+
|
| 84 |
+
th = {"ik_warn": a.ik_warn, "ik_fail": a.ik_fail, "ori_warn": a.ori_warn,
|
| 85 |
+
"ori_fail": a.ori_fail, "arms": a.arms, "motion": a.motion}
|
| 86 |
+
exclude_set = _excluded_ids(a.report, th) if (a.exclude and a.report) else set()
|
| 87 |
+
if exclude_set:
|
| 88 |
+
print(f"[exclude] user opted to drop {len(exclude_set)} FAIL-flagged clips", file=sys.stderr)
|
| 89 |
|
| 90 |
# Pass 1 — resolve each retargeted clip to (cat, ep, chunk, file) and symlink it into the
|
| 91 |
# category layout. Cheap (local hdf5 attrs + cached meta parquets), so keep it sequential.
|
|
|
|
| 95 |
with h5py.File(hp, "r") as h:
|
| 96 |
cat = str(h.attrs["task"])
|
| 97 |
ep = int(str(h.attrs["clip"]).split("-")[1])
|
| 98 |
+
if f"{cat}#{ep}" in exclude_set: # user opted to drop this FAIL-flagged clip
|
| 99 |
+
excluded += 1
|
| 100 |
+
continue
|
| 101 |
r = tb._episode_range(cache, cat, ep)
|
| 102 |
ci, fi = r["data/chunk_index"], r["data/file_index"]
|
| 103 |
fyy = f"file-{fi:03d}"
|
|
|
|
| 136 |
with ThreadPoolExecutor(max_workers=min(24, max(1, len(uniq)))) as ex:
|
| 137 |
vids = sum(1 for ok in ex.map(_dlvid, uniq) if ok)
|
| 138 |
|
| 139 |
+
print(json.dumps({"clips": done, "videos": vids, "skipped": skipped, "excluded": excluded,
|
| 140 |
"retgt": a.retgt_out, "ego": str(ego_root)}))
|
| 141 |
|
| 142 |
|