#!/usr/bin/env python3 """Rebuild the per-sequence tars from the original frame tree. The tars that get uploaded to the Hub are derived data - they are deleted locally once uploaded. This regenerates them byte-for-byte identically. python repack_for_upload.py --src ../../vqs_4k_kaggle --out .. `metadata.csv` carries both ids, so the rename (legacy_seq_id -> seq_id) is applied to the archive name AND to the paths inside it. """ import argparse import csv import os import subprocess from multiprocessing import Pool from pathlib import Path def repack(job): src, out, kind, old, new = job dst = Path(out) / kind / f"{new}.tar" if dst.exists(): return None tmp = str(dst) + ".part" cmd = ["tar", "--sort=name", "--owner=0", "--group=0", "--mtime=UTC 2026-01-01", f"--transform=s|^{old}|{new}|", "-cf", tmp, "-C", f"{src}/{kind}", old] r = subprocess.run(cmd, capture_output=True) if r.returncode != 0: Path(tmp).exists() and os.remove(tmp) return f"FAIL {kind}/{old}: {r.stderr.decode()[:120]}" os.replace(tmp, dst) return None def main(): p = argparse.ArgumentParser() p.add_argument("--src", required=True, help="original tree with images// and masks//") p.add_argument("--out", default=".", help="where to write images/*.tar and masks/*.tar") p.add_argument("--workers", type=int, default=6) a = p.parse_args() meta = Path(a.out) / "metadata.csv" rows = list(csv.DictReader(open(meta))) for k in ("images", "masks"): (Path(a.out) / k).mkdir(parents=True, exist_ok=True) jobs = [(a.src, a.out, k, r["legacy_seq_id"], r["seq_id"]) for k in ("masks", "images") for r in rows] print(f"packing {len(jobs)} archives from {a.src}") with Pool(a.workers) as pool: errs = [e for e in pool.imap_unordered(repack, jobs, chunksize=8) if e] print("errors:", len(errs)) for e in errs[:5]: print(" ", e) if __name__ == "__main__": main()