Upload prep_lerobot.py with huggingface_hub
Browse files- prep_lerobot.py +20 -7
prep_lerobot.py
CHANGED
|
@@ -24,6 +24,7 @@ import glob
|
|
| 24 |
import json
|
| 25 |
import os
|
| 26 |
import sys
|
|
|
|
| 27 |
from pathlib import Path
|
| 28 |
|
| 29 |
import h5py
|
|
@@ -43,6 +44,9 @@ def main():
|
|
| 43 |
ego_root = cache / tb.REPO.replace("/", "__") # to_lerobot EGO = this (<cat>/videos + meta)
|
| 44 |
done, vids, skipped = 0, 0, 0
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
for hp in sorted(glob.glob(f"{a.flat}/*/retargeted.hdf5")):
|
| 47 |
try:
|
| 48 |
with h5py.File(hp, "r") as h:
|
|
@@ -52,7 +56,6 @@ def main():
|
|
| 52 |
ci, fi = r["data/chunk_index"], r["data/file_index"]
|
| 53 |
fyy = f"file-{fi:03d}"
|
| 54 |
|
| 55 |
-
# 1) retargeted → category layout with the file-FFF_epN name to_lerobot parses
|
| 56 |
dst = Path(a.retgt_out) / cat / f"clip_{fyy}_ep{ep}"
|
| 57 |
dst.mkdir(parents=True, exist_ok=True)
|
| 58 |
link = dst / "retargeted.hdf5"
|
|
@@ -60,18 +63,28 @@ def main():
|
|
| 60 |
link.unlink()
|
| 61 |
os.symlink(os.path.abspath(hp), link)
|
| 62 |
|
| 63 |
-
# 2) download this clip's ego video (into cache, same repo layout)
|
| 64 |
vid_rel = f"{tb.PREFIX}{cat}/videos/observation.images.camera/chunk-{ci:03d}/{fyy}.mp4"
|
| 65 |
-
|
| 66 |
-
tb._ensure(cache, vid_rel)
|
| 67 |
-
vids += 1
|
| 68 |
-
except Exception as e:
|
| 69 |
-
print(f"[warn] video dl {vid_rel}: {e}", file=sys.stderr)
|
| 70 |
done += 1
|
| 71 |
except Exception as e:
|
| 72 |
skipped += 1
|
| 73 |
print(f"[warn] {hp}: {e}", file=sys.stderr)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
print(json.dumps({"clips": done, "videos": vids, "skipped": skipped,
|
| 76 |
"retgt": a.retgt_out, "ego": str(ego_root)}))
|
| 77 |
|
|
|
|
| 24 |
import json
|
| 25 |
import os
|
| 26 |
import sys
|
| 27 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 28 |
from pathlib import Path
|
| 29 |
|
| 30 |
import h5py
|
|
|
|
| 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.
|
| 49 |
+
items = [] # (cat, ep, ci, fi, vid_rel)
|
| 50 |
for hp in sorted(glob.glob(f"{a.flat}/*/retargeted.hdf5")):
|
| 51 |
try:
|
| 52 |
with h5py.File(hp, "r") as h:
|
|
|
|
| 56 |
ci, fi = r["data/chunk_index"], r["data/file_index"]
|
| 57 |
fyy = f"file-{fi:03d}"
|
| 58 |
|
|
|
|
| 59 |
dst = Path(a.retgt_out) / cat / f"clip_{fyy}_ep{ep}"
|
| 60 |
dst.mkdir(parents=True, exist_ok=True)
|
| 61 |
link = dst / "retargeted.hdf5"
|
|
|
|
| 63 |
link.unlink()
|
| 64 |
os.symlink(os.path.abspath(hp), link)
|
| 65 |
|
|
|
|
| 66 |
vid_rel = f"{tb.PREFIX}{cat}/videos/observation.images.camera/chunk-{ci:03d}/{fyy}.mp4"
|
| 67 |
+
items.append(vid_rel)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
done += 1
|
| 69 |
except Exception as e:
|
| 70 |
skipped += 1
|
| 71 |
print(f"[warn] {hp}: {e}", file=sys.stderr)
|
| 72 |
|
| 73 |
+
# Pass 2 — download the ego VIDEOS in PARALLEL (transform only fetched keypoints). These are the
|
| 74 |
+
# big files; a sequential loop dominated packaging wall-clock. Dedup + bounded per-file timeout
|
| 75 |
+
# in tb._ensure make concurrent fetches safe. A failed video is a non-fatal warn.
|
| 76 |
+
def _dlvid(vid_rel: str) -> bool:
|
| 77 |
+
try:
|
| 78 |
+
tb._ensure(cache, vid_rel)
|
| 79 |
+
return True
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"[warn] video dl {vid_rel}: {e}", file=sys.stderr)
|
| 82 |
+
return False
|
| 83 |
+
|
| 84 |
+
uniq = list(dict.fromkeys(items)) # preserve order, drop dup video files
|
| 85 |
+
with ThreadPoolExecutor(max_workers=min(24, max(1, len(uniq)))) as ex:
|
| 86 |
+
vids = sum(1 for ok in ex.map(_dlvid, uniq) if ok)
|
| 87 |
+
|
| 88 |
print(json.dumps({"clips": done, "videos": vids, "skipped": skipped,
|
| 89 |
"retgt": a.retgt_out, "ego": str(ego_root)}))
|
| 90 |
|