Upload folder using huggingface_hub
Browse files- scripts/build_index.py +43 -0
- scripts/extract_frames.py +107 -0
- scripts/fetch_clips.py +142 -0
- scripts/hfzip.py +94 -0
- scripts/motion_cut.py +48 -0
- scripts/select_clips.py +116 -0
- scripts/verify_dataset.py +74 -0
scripts/build_index.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, os, sys, time, requests
|
| 2 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 3 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 4 |
+
from hfzip import open_part
|
| 5 |
+
|
| 6 |
+
OUT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "meta", "part_index.jsonl")
|
| 7 |
+
|
| 8 |
+
def index_part(i):
|
| 9 |
+
s = requests.Session()
|
| 10 |
+
for attempt in range(4):
|
| 11 |
+
try:
|
| 12 |
+
z, rf = open_part(i, s)
|
| 13 |
+
return i, [(n, z.getinfo(n).compress_size)
|
| 14 |
+
for n in z.namelist() if n.endswith(".mp4")], rf.bytes_fetched
|
| 15 |
+
except Exception as e:
|
| 16 |
+
if attempt == 3:
|
| 17 |
+
return i, None, 0
|
| 18 |
+
time.sleep(3 * (attempt + 1))
|
| 19 |
+
|
| 20 |
+
# resume: skip parts already fully written
|
| 21 |
+
done = set()
|
| 22 |
+
if os.path.exists(OUT):
|
| 23 |
+
with open(OUT) as f:
|
| 24 |
+
for line in f:
|
| 25 |
+
try: done.add(json.loads(line)["part"])
|
| 26 |
+
except Exception: pass
|
| 27 |
+
todo = [i for i in range(186) if i not in done]
|
| 28 |
+
print(f"already indexed parts: {len(done)}, todo: {len(todo)}", flush=True)
|
| 29 |
+
|
| 30 |
+
fails = []
|
| 31 |
+
with open(OUT, "a") as out, ThreadPoolExecutor(max_workers=10) as ex:
|
| 32 |
+
futs = [ex.submit(index_part, i) for i in todo]
|
| 33 |
+
for fut in as_completed(futs):
|
| 34 |
+
i, members, nb = fut.result()
|
| 35 |
+
if members is None:
|
| 36 |
+
print(f"[FAIL] part{i}", flush=True); fails.append(i); continue
|
| 37 |
+
for m, csz in members:
|
| 38 |
+
out.write(json.dumps({"clip": m.split("/")[-1], "part": i,
|
| 39 |
+
"member": m, "bytes": csz}) + "\n")
|
| 40 |
+
out.flush()
|
| 41 |
+
print(f"part{i}: {len(members)} clips ({nb/1e6:.1f} MB read)", flush=True)
|
| 42 |
+
print("FAILED_PARTS:", fails, flush=True)
|
| 43 |
+
print("INDEX_DONE", flush=True)
|
scripts/extract_frames.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse, csv, hashlib, json, os, subprocess, sys, time
|
| 2 |
+
from concurrent.futures import ProcessPoolExecutor, as_completed
|
| 3 |
+
|
| 4 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 5 |
+
csv.field_size_limit(10**9)
|
| 6 |
+
|
| 7 |
+
ap = argparse.ArgumentParser()
|
| 8 |
+
ap.add_argument("--manifest", default=os.path.join(ROOT, "meta", "manifest.csv"))
|
| 9 |
+
ap.add_argument("--videos", default=os.path.join(ROOT, "videos"))
|
| 10 |
+
ap.add_argument("--frames", default=os.path.join(ROOT, "frames"))
|
| 11 |
+
ap.add_argument("--out", default=os.path.join(ROOT, "sequences.jsonl"))
|
| 12 |
+
ap.add_argument("--n-frames", type=int, default=10)
|
| 13 |
+
ap.add_argument("--step", type=float, default=0.5)
|
| 14 |
+
ap.add_argument("--width", type=int, default=768)
|
| 15 |
+
ap.add_argument("--quality", type=int, default=3)
|
| 16 |
+
ap.add_argument("--workers", type=int, default=max(1, os.cpu_count() - 8))
|
| 17 |
+
ap.add_argument("--limit", type=int, default=None)
|
| 18 |
+
A = ap.parse_args()
|
| 19 |
+
|
| 20 |
+
N, STEP, W, Q = A.n_frames, A.step, A.width, A.quality
|
| 21 |
+
WINDOW_SEC = N * STEP # start-to-start distance between windows (5.0 s)
|
| 22 |
+
|
| 23 |
+
def shard(seq_id):
|
| 24 |
+
return hashlib.md5(seq_id.encode()).hexdigest()[:2] # 256 buckets
|
| 25 |
+
|
| 26 |
+
def rel_dir(seq_id):
|
| 27 |
+
return os.path.join("frames", shard(seq_id), seq_id)
|
| 28 |
+
|
| 29 |
+
def extract_window(video_path, out_abs, start):
|
| 30 |
+
os.makedirs(out_abs, exist_ok=True)
|
| 31 |
+
have = sorted(f for f in os.listdir(out_abs) if f.endswith(".jpg"))
|
| 32 |
+
if len(have) >= N:
|
| 33 |
+
return "skip"
|
| 34 |
+
for f in have: # partial -> redo cleanly
|
| 35 |
+
os.remove(os.path.join(out_abs, f))
|
| 36 |
+
subprocess.run(
|
| 37 |
+
["ffmpeg", "-v", "error", "-ss", str(start), "-i", video_path,
|
| 38 |
+
# eof_action=pass: without it the fps filter drops the final frame on clips
|
| 39 |
+
# whose duration only just covers the window (the N*STEP boundary cases).
|
| 40 |
+
"-vf", f"fps={1/STEP}:eof_action=pass,scale={W}:-2:flags=lanczos",
|
| 41 |
+
"-frames:v", str(N), "-q:v", str(Q),
|
| 42 |
+
"-start_number", "0", # ffmpeg defaults to 1 -> would break f00.jpg paths
|
| 43 |
+
os.path.join(out_abs, "f%02d.jpg"), "-y"],
|
| 44 |
+
check=True, stdin=subprocess.DEVNULL,
|
| 45 |
+
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
| 46 |
+
n = len([f for f in os.listdir(out_abs) if f.endswith(".jpg")])
|
| 47 |
+
return "ok" if n == N else f"short:{n}"
|
| 48 |
+
|
| 49 |
+
def job(row):
|
| 50 |
+
vp = os.path.join(A.videos, row["video"])
|
| 51 |
+
if not os.path.exists(vp):
|
| 52 |
+
return []
|
| 53 |
+
stem, out = row["video"][:-4], []
|
| 54 |
+
for w in range(int(row["windows"])):
|
| 55 |
+
start = w * WINDOW_SEC
|
| 56 |
+
seq_id = f"{stem}__w{w}"
|
| 57 |
+
rd = rel_dir(seq_id)
|
| 58 |
+
od = os.path.join(ROOT, rd)
|
| 59 |
+
try:
|
| 60 |
+
st = extract_window(vp, od, start)
|
| 61 |
+
except subprocess.CalledProcessError:
|
| 62 |
+
continue
|
| 63 |
+
except Exception:
|
| 64 |
+
continue
|
| 65 |
+
if st.startswith("short"):
|
| 66 |
+
try:
|
| 67 |
+
for f in os.listdir(od): os.remove(os.path.join(od, f))
|
| 68 |
+
os.rmdir(od)
|
| 69 |
+
except Exception: pass
|
| 70 |
+
continue
|
| 71 |
+
out.append({
|
| 72 |
+
"id": seq_id,
|
| 73 |
+
"video": row["video"],
|
| 74 |
+
"frames": [f"{rd}/f{i:02d}.jpg" for i in range(N)],
|
| 75 |
+
"timestamps": [round(start + i * STEP, 2) for i in range(N)],
|
| 76 |
+
"step_sec": STEP,
|
| 77 |
+
"n_frames": N,
|
| 78 |
+
"video_caption": row["caption"],
|
| 79 |
+
"meta": {k: row[k] for k in ("seconds", "fps", "motion",
|
| 80 |
+
"aesthetic", "camera", "hd")},
|
| 81 |
+
})
|
| 82 |
+
return out
|
| 83 |
+
|
| 84 |
+
rows = list(csv.DictReader(open(A.manifest, newline="")))
|
| 85 |
+
rows = [r for r in rows if os.path.exists(os.path.join(A.videos, r["video"]))]
|
| 86 |
+
if A.limit:
|
| 87 |
+
rows = rows[:A.limit]
|
| 88 |
+
print(f"clips on disk: {len(rows):,} workers: {A.workers} -> {A.out}", flush=True)
|
| 89 |
+
|
| 90 |
+
t0, n, done = time.time(), 0, 0
|
| 91 |
+
with open(A.out, "w") as f, ProcessPoolExecutor(A.workers) as ex:
|
| 92 |
+
futs = [ex.submit(job, r) for r in rows]
|
| 93 |
+
for fut in as_completed(futs):
|
| 94 |
+
done += 1
|
| 95 |
+
try:
|
| 96 |
+
recs = fut.result()
|
| 97 |
+
except Exception as e:
|
| 98 |
+
print(f" [ERR] {e}", flush=True); continue
|
| 99 |
+
for rec in recs:
|
| 100 |
+
f.write(json.dumps(rec, ensure_ascii=False) + "\n"); n += 1
|
| 101 |
+
if done % 500 == 0:
|
| 102 |
+
el = time.time() - t0
|
| 103 |
+
print(f"[{time.strftime('%H:%M:%S')}] clips {done:,}/{len(rows):,} "
|
| 104 |
+
f"seqs {n:,} {done/el:.1f} clip/s "
|
| 105 |
+
f"ETA {(len(rows)-done)/(done/el)/60:.1f} min", flush=True)
|
| 106 |
+
f.flush()
|
| 107 |
+
print(f"DONE {n:,} sequences -> {n * (N - 1):,} adjacent frame pairs", flush=True)
|
scripts/fetch_clips.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse, collections, csv, json, os, sys, threading, time
|
| 2 |
+
import requests
|
| 3 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 4 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 5 |
+
from hfzip import open_part, make_session, read_member
|
| 6 |
+
|
| 7 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 8 |
+
csv.field_size_limit(10**9)
|
| 9 |
+
|
| 10 |
+
ap = argparse.ArgumentParser()
|
| 11 |
+
ap.add_argument("--manifest", default=os.path.join(ROOT, "meta", "manifest.csv"))
|
| 12 |
+
ap.add_argument("--budget-gb", type=float, default=None)
|
| 13 |
+
ap.add_argument("--out", default=os.path.join(ROOT, "videos"))
|
| 14 |
+
ap.add_argument("--workers", type=int, default=16)
|
| 15 |
+
ap.add_argument("--chunk", type=int, default=150, help="clips per worker task (allows >1 thread per zip part)")
|
| 16 |
+
ap.add_argument("--limit", type=int, default=None, help="benchmark: only first N clips")
|
| 17 |
+
ap.add_argument("--retries", type=int, default=4)
|
| 18 |
+
args = ap.parse_args()
|
| 19 |
+
|
| 20 |
+
os.makedirs(args.out, exist_ok=True)
|
| 21 |
+
|
| 22 |
+
jobs = []
|
| 23 |
+
with open(args.manifest, newline="") as f:
|
| 24 |
+
for r in csv.DictReader(f):
|
| 25 |
+
if args.budget_gb and float(r["cum_gb"]) > args.budget_gb:
|
| 26 |
+
break
|
| 27 |
+
jobs.append({"video": r["video"], "member": r["member"],
|
| 28 |
+
"part": int(r["part"]), "bytes": int(r["bytes"])})
|
| 29 |
+
if args.limit:
|
| 30 |
+
jobs = jobs[:args.limit]
|
| 31 |
+
|
| 32 |
+
total_jobs = len(jobs)
|
| 33 |
+
total_bytes = sum(j["bytes"] for j in jobs)
|
| 34 |
+
jobs = [j for j in jobs if not os.path.exists(os.path.join(args.out, j["video"]))]
|
| 35 |
+
print(f"manifest jobs: {total_jobs:,} ({total_bytes/1e9:.1f} GB) | todo: {len(jobs):,} "
|
| 36 |
+
f"({sum(j['bytes'] for j in jobs)/1e9:.1f} GB) | already on disk: {total_jobs-len(jobs):,}", flush=True)
|
| 37 |
+
|
| 38 |
+
by_part = collections.defaultdict(list)
|
| 39 |
+
for j in jobs:
|
| 40 |
+
by_part[j["part"]].append(j)
|
| 41 |
+
|
| 42 |
+
# split each part's jobs into chunks -> several threads may work the same part
|
| 43 |
+
tasks = []
|
| 44 |
+
for p, js in sorted(by_part.items()):
|
| 45 |
+
for k in range(0, len(js), args.chunk):
|
| 46 |
+
tasks.append((p, js[k:k+args.chunk]))
|
| 47 |
+
tasks.sort(key=lambda t: -len(t[1]))
|
| 48 |
+
print(f"parts: {len(by_part)} | tasks: {len(tasks)} | workers: {args.workers}", flush=True)
|
| 49 |
+
|
| 50 |
+
LOCK = threading.Lock()
|
| 51 |
+
THROTTLE_UNTIL = [0.0]
|
| 52 |
+
|
| 53 |
+
def note_throttle(e, secs=20):
|
| 54 |
+
"""Global brake: when HF starts 429-ing, every thread pauses."""
|
| 55 |
+
if "429" in str(e) or "Too Many Requests" in str(e):
|
| 56 |
+
with LOCK:
|
| 57 |
+
THROTTLE_UNTIL[0] = max(THROTTLE_UNTIL[0], time.time() + secs)
|
| 58 |
+
|
| 59 |
+
def wait_throttle():
|
| 60 |
+
while True:
|
| 61 |
+
with LOCK:
|
| 62 |
+
t = THROTTLE_UNTIL[0]
|
| 63 |
+
d = t - time.time()
|
| 64 |
+
if d <= 0:
|
| 65 |
+
return
|
| 66 |
+
time.sleep(min(d, 5))
|
| 67 |
+
STAT = dict(got=0, failed=0, nbytes=0, t0=time.time())
|
| 68 |
+
STOP = threading.Event()
|
| 69 |
+
|
| 70 |
+
def bump(got=0, failed=0, nbytes=0):
|
| 71 |
+
with LOCK:
|
| 72 |
+
STAT["got"] += got; STAT["failed"] += failed; STAT["nbytes"] += nbytes
|
| 73 |
+
|
| 74 |
+
def reporter():
|
| 75 |
+
last = 0
|
| 76 |
+
while not STOP.wait(30):
|
| 77 |
+
with LOCK:
|
| 78 |
+
g, fl, nb, t0 = STAT["got"], STAT["failed"], STAT["nbytes"], STAT["t0"]
|
| 79 |
+
el = time.time() - t0
|
| 80 |
+
inst = (nb - last) / 30 / 1e6
|
| 81 |
+
last = nb
|
| 82 |
+
eta = (len(jobs) - g) / (g / el) / 3600 if g else float("nan")
|
| 83 |
+
print(f"[{time.strftime('%H:%M:%S')}] {g:,}/{len(jobs):,} clips {nb/1e9:.1f} GB "
|
| 84 |
+
f"avg {nb/el/1e6:.0f} MB/s now {inst:.0f} MB/s fail {fl} ETA {eta:.1f} h", flush=True)
|
| 85 |
+
|
| 86 |
+
def fetch_task(part, todo):
|
| 87 |
+
s = make_session()
|
| 88 |
+
z = rf = None
|
| 89 |
+
for attempt in range(args.retries):
|
| 90 |
+
try:
|
| 91 |
+
z, rf = open_part(part, s); break
|
| 92 |
+
except Exception as e:
|
| 93 |
+
if attempt == args.retries - 1:
|
| 94 |
+
bump(failed=len(todo))
|
| 95 |
+
return part, 0, len(todo), f"open_part failed: {e}"
|
| 96 |
+
time.sleep(3 * (attempt + 1))
|
| 97 |
+
got = failed = 0
|
| 98 |
+
for j in todo:
|
| 99 |
+
wait_throttle()
|
| 100 |
+
dst = os.path.join(args.out, j["video"])
|
| 101 |
+
if os.path.exists(dst):
|
| 102 |
+
continue
|
| 103 |
+
tmp = dst + f".part{threading.get_ident()}"
|
| 104 |
+
for attempt in range(args.retries):
|
| 105 |
+
try:
|
| 106 |
+
data = read_member(z, rf, j["member"])
|
| 107 |
+
with open(tmp, "wb") as fh:
|
| 108 |
+
fh.write(data)
|
| 109 |
+
os.replace(tmp, dst)
|
| 110 |
+
got += 1
|
| 111 |
+
bump(got=1, nbytes=len(data))
|
| 112 |
+
break
|
| 113 |
+
except Exception as e:
|
| 114 |
+
note_throttle(e)
|
| 115 |
+
try: os.path.exists(tmp) and os.remove(tmp)
|
| 116 |
+
except Exception: pass
|
| 117 |
+
if attempt == args.retries - 1:
|
| 118 |
+
failed += 1; bump(failed=1)
|
| 119 |
+
print(f" [FAIL] {j['video']} part{part}: {e}", flush=True)
|
| 120 |
+
else:
|
| 121 |
+
wait_throttle()
|
| 122 |
+
time.sleep(3 * (attempt + 1))
|
| 123 |
+
try:
|
| 124 |
+
z, rf = open_part(part, s) # re-open on error
|
| 125 |
+
except Exception:
|
| 126 |
+
pass
|
| 127 |
+
return part, got, failed, "ok"
|
| 128 |
+
|
| 129 |
+
th = threading.Thread(target=reporter, daemon=True); th.start()
|
| 130 |
+
with ThreadPoolExecutor(max_workers=args.workers) as ex:
|
| 131 |
+
futs = [ex.submit(fetch_task, p, js) for p, js in tasks]
|
| 132 |
+
done = 0
|
| 133 |
+
for fut in as_completed(futs):
|
| 134 |
+
done += 1
|
| 135 |
+
try:
|
| 136 |
+
fut.result()
|
| 137 |
+
except Exception as e:
|
| 138 |
+
print(f" [TASK ERR] {e}", flush=True)
|
| 139 |
+
STOP.set()
|
| 140 |
+
el = time.time() - STAT["t0"]
|
| 141 |
+
print(f"DONE got={STAT['got']:,} failed={STAT['failed']:,} "
|
| 142 |
+
f"{STAT['nbytes']/1e9:.1f} GB in {el/60:.1f} min ({STAT['nbytes']/el/1e6:.0f} MB/s)", flush=True)
|
scripts/hfzip.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io, struct, zipfile, zlib, requests
|
| 2 |
+
from requests.adapters import HTTPAdapter
|
| 3 |
+
from urllib3.util.retry import Retry
|
| 4 |
+
|
| 5 |
+
HF = "https://huggingface.co/datasets/nkp37/OpenVid-1M/resolve/main"
|
| 6 |
+
|
| 7 |
+
def make_session(total=10, backoff=1.5):
|
| 8 |
+
"""Session that transparently retries 429/5xx with exponential backoff,
|
| 9 |
+
honouring Retry-After when HF sends it."""
|
| 10 |
+
s = requests.Session()
|
| 11 |
+
r = Retry(total=total, connect=total, read=total, status=total,
|
| 12 |
+
backoff_factor=backoff,
|
| 13 |
+
status_forcelist=[429, 500, 502, 503, 504],
|
| 14 |
+
allowed_methods=["GET", "HEAD"],
|
| 15 |
+
respect_retry_after_header=True,
|
| 16 |
+
raise_on_status=False)
|
| 17 |
+
ad = HTTPAdapter(max_retries=r, pool_connections=64, pool_maxsize=64)
|
| 18 |
+
s.mount("https://", ad); s.mount("http://", ad)
|
| 19 |
+
return s
|
| 20 |
+
SPLIT_PARTS = {73,76,78,83,88,89,92,95,96,102,103,111,118,183,184,185}
|
| 21 |
+
|
| 22 |
+
def part_urls(i):
|
| 23 |
+
if i in SPLIT_PARTS:
|
| 24 |
+
return [f"{HF}/OpenVid_part{i}_partaa", f"{HF}/OpenVid_part{i}_partab"]
|
| 25 |
+
return [f"{HF}/OpenVid_part{i}.zip"]
|
| 26 |
+
|
| 27 |
+
class RangeFile(io.RawIOBase):
|
| 28 |
+
"""Several URLs concatenated into one seekable read-only file."""
|
| 29 |
+
def __init__(self, urls, session=None, timeout=60):
|
| 30 |
+
self.urls, self.s, self.timeout = list(urls), session or make_session(), timeout
|
| 31 |
+
self.sizes = [int(self.s.head(u, allow_redirects=True, timeout=timeout)
|
| 32 |
+
.headers["Content-Length"]) for u in self.urls]
|
| 33 |
+
self.offs, acc = [], 0
|
| 34 |
+
for sz in self.sizes:
|
| 35 |
+
self.offs.append(acc); acc += sz
|
| 36 |
+
self.size, self.pos, self.bytes_fetched = acc, 0, 0
|
| 37 |
+
|
| 38 |
+
def seek(self, off, whence=0):
|
| 39 |
+
self.pos = off if whence == 0 else (self.pos + off if whence == 1 else self.size + off)
|
| 40 |
+
return self.pos
|
| 41 |
+
def tell(self): return self.pos
|
| 42 |
+
def seekable(self): return True
|
| 43 |
+
def readable(self): return True
|
| 44 |
+
|
| 45 |
+
def read(self, n=-1):
|
| 46 |
+
n = self.size - self.pos if (n is None or n < 0) else min(n, self.size - self.pos)
|
| 47 |
+
if n <= 0: return b""
|
| 48 |
+
out = bytearray()
|
| 49 |
+
while n > 0:
|
| 50 |
+
k = max(j for j, o in enumerate(self.offs) if o <= self.pos)
|
| 51 |
+
local = self.pos - self.offs[k]
|
| 52 |
+
take = min(n, self.sizes[k] - local)
|
| 53 |
+
r = self.s.get(self.urls[k], headers={"Range": f"bytes={local}-{local+take-1}"},
|
| 54 |
+
allow_redirects=True, timeout=self.timeout)
|
| 55 |
+
r.raise_for_status()
|
| 56 |
+
out += r.content
|
| 57 |
+
self.pos += len(r.content); n -= len(r.content); self.bytes_fetched += len(r.content)
|
| 58 |
+
if len(r.content) < take: break
|
| 59 |
+
return bytes(out)
|
| 60 |
+
|
| 61 |
+
def open_part(i, session=None):
|
| 62 |
+
rf = RangeFile(part_urls(i), session or make_session())
|
| 63 |
+
return zipfile.ZipFile(rf), rf
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def read_member(z, rf, member):
|
| 67 |
+
"""Read one zip member with a SINGLE HTTP Range request.
|
| 68 |
+
|
| 69 |
+
zipfile.ZipFile.read() costs 3-4 round trips per member (local header, file
|
| 70 |
+
name, extra field, payload). Over HTTP that is latency- and request-rate-
|
| 71 |
+
bound, and HF throttles on request count, so we fetch
|
| 72 |
+
[local header .. end of payload] in one go and parse the 30-byte header
|
| 73 |
+
locally. Members are deflated; zlib with a raw (-15) window undoes that.
|
| 74 |
+
"""
|
| 75 |
+
zi = z.getinfo(member)
|
| 76 |
+
if zi.compress_type not in (zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED):
|
| 77 |
+
return z.read(member) # exotic method: stay correct
|
| 78 |
+
SLACK = 30 + 1024 # header + filename + extra
|
| 79 |
+
rf.seek(zi.header_offset)
|
| 80 |
+
blob = rf.read(SLACK + zi.compress_size)
|
| 81 |
+
if len(blob) < 30 or blob[:4] != b"PK\x03\x04":
|
| 82 |
+
raise IOError(f"bad local header for {member}")
|
| 83 |
+
fnl, exl = struct.unpack("<HH", blob[26:30])
|
| 84 |
+
off = 30 + fnl + exl
|
| 85 |
+
raw = blob[off:off + zi.compress_size]
|
| 86 |
+
if len(raw) < zi.compress_size: # filename+extra > SLACK
|
| 87 |
+
rf.seek(zi.header_offset + off + len(raw))
|
| 88 |
+
raw += rf.read(zi.compress_size - len(raw))
|
| 89 |
+
if len(raw) != zi.compress_size:
|
| 90 |
+
raise IOError(f"short read {member}: {len(raw)}/{zi.compress_size}")
|
| 91 |
+
data = raw if zi.compress_type == zipfile.ZIP_STORED else zlib.decompress(raw, -15)
|
| 92 |
+
if len(data) != zi.file_size:
|
| 93 |
+
raise IOError(f"bad size {member}: {len(data)}/{zi.file_size}")
|
| 94 |
+
return data
|
scripts/motion_cut.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Print the motion-score percentile ladder of the candidate pool.
|
| 2 |
+
|
| 3 |
+
The pool is everything select_clips.py would keep *except* the motion cut, so the
|
| 4 |
+
number printed here is exactly the value to pass as --motion-lo.
|
| 5 |
+
"""
|
| 6 |
+
import argparse, csv, json, os, re, bisect
|
| 7 |
+
|
| 8 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 9 |
+
META = os.path.join(ROOT, "meta")
|
| 10 |
+
csv.field_size_limit(10**9)
|
| 11 |
+
TALKING = re.compile(r"\b(talk|talks|talking|interview|interviews|interviewed|"
|
| 12 |
+
r"podcast|podcasts)\b", re.I)
|
| 13 |
+
|
| 14 |
+
ap = argparse.ArgumentParser()
|
| 15 |
+
ap.add_argument("--n-frames", type=int, default=10)
|
| 16 |
+
ap.add_argument("--step", type=float, default=0.5)
|
| 17 |
+
ap.add_argument("--margin", type=float, default=0.25)
|
| 18 |
+
ap.add_argument("--motion-hi", type=float, default=60.0)
|
| 19 |
+
ap.add_argument("--min-aesthetic", type=float, default=5.0)
|
| 20 |
+
ap.add_argument("--keep-talking", action="store_true")
|
| 21 |
+
ap.add_argument("--at", type=float, default=None, help="report the percentile of this score")
|
| 22 |
+
A = ap.parse_args()
|
| 23 |
+
MIN_SEC = (A.n_frames - 1) * A.step + A.margin
|
| 24 |
+
|
| 25 |
+
idx = {json.loads(l)["clip"] for l in open(os.path.join(META, "part_index.jsonl"))}
|
| 26 |
+
mot = []
|
| 27 |
+
with open(os.path.join(META, "OpenVid-1M.csv"), newline="") as f:
|
| 28 |
+
for r in csv.DictReader(f):
|
| 29 |
+
v = r["video"]
|
| 30 |
+
if v.startswith(("celebv_", "pixabay_")) or v not in idx:
|
| 31 |
+
continue
|
| 32 |
+
try:
|
| 33 |
+
m, sec, aes = float(r["motion score"]), float(r["seconds"]), float(r["aesthetic score"])
|
| 34 |
+
except ValueError:
|
| 35 |
+
continue
|
| 36 |
+
if sec < MIN_SEC or m > A.motion_hi or aes < A.min_aesthetic:
|
| 37 |
+
continue
|
| 38 |
+
if not A.keep_talking and TALKING.search(r["caption"]):
|
| 39 |
+
continue
|
| 40 |
+
mot.append(m)
|
| 41 |
+
|
| 42 |
+
mot.sort()
|
| 43 |
+
n = len(mot)
|
| 44 |
+
print(f"candidate pool (no motion cut): {n:,} clips")
|
| 45 |
+
for top in (10, 20, 30, 40, 50, 70, 100):
|
| 46 |
+
print(f" top {top:>3}% -> motion >= {mot[int(n * (1 - top/100))]:.4f}")
|
| 47 |
+
if A.at is not None:
|
| 48 |
+
print(f" motion {A.at} sits at top {100 - bisect.bisect_left(mot, A.at)*100/n:.1f}%")
|
scripts/select_clips.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse, csv, hashlib, json, os, re
|
| 2 |
+
|
| 3 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 4 |
+
META = os.path.join(ROOT, "meta")
|
| 5 |
+
csv.field_size_limit(10**9)
|
| 6 |
+
|
| 7 |
+
# Only the "a person is talking at the camera" cases: those clips can carry a high
|
| 8 |
+
# motion score (lip/hand movement) while nothing in the scene actually changes.
|
| 9 |
+
TALKING = re.compile(r"\b(talk|talks|talking|interview|interviews|interviewed|"
|
| 10 |
+
r"podcast|podcasts)\b", re.I)
|
| 11 |
+
|
| 12 |
+
p = argparse.ArgumentParser()
|
| 13 |
+
p.add_argument("--n-frames", type=int, default=10)
|
| 14 |
+
p.add_argument("--step", type=float, default=0.5)
|
| 15 |
+
p.add_argument("--max-windows", type=int, default=2,
|
| 16 |
+
help="hard cap on sequences taken from one clip")
|
| 17 |
+
p.add_argument("--margin", type=float, default=0.25,
|
| 18 |
+
help="seconds of slack required past the last frame of a window")
|
| 19 |
+
p.add_argument("--motion-lo", type=float, default=5.27)
|
| 20 |
+
p.add_argument("--motion-hi", type=float, default=60.0)
|
| 21 |
+
p.add_argument("--min-aesthetic", type=float, default=5.0)
|
| 22 |
+
p.add_argument("--keep-talking", action="store_true")
|
| 23 |
+
p.add_argument("--order", choices=["efficiency", "shuffle", "quality"], default="efficiency")
|
| 24 |
+
p.add_argument("--out", default=os.path.join(META, "manifest.csv"))
|
| 25 |
+
args = p.parse_args()
|
| 26 |
+
|
| 27 |
+
SPAN = (args.n_frames - 1) * args.step # first frame -> last frame
|
| 28 |
+
SLOT = args.n_frames * args.step # start-to-start distance between windows
|
| 29 |
+
|
| 30 |
+
def n_windows(sec):
|
| 31 |
+
"""How many non-overlapping windows fit, capped at --max-windows."""
|
| 32 |
+
w = 0
|
| 33 |
+
while w < args.max_windows and sec >= w * SLOT + SPAN + args.margin:
|
| 34 |
+
w += 1
|
| 35 |
+
return w
|
| 36 |
+
|
| 37 |
+
print("loading part index ...", flush=True)
|
| 38 |
+
idx = {}
|
| 39 |
+
with open(os.path.join(META, "part_index.jsonl")) as f:
|
| 40 |
+
for line in f:
|
| 41 |
+
d = json.loads(line)
|
| 42 |
+
idx[d["clip"]] = (d["part"], d["member"], d["bytes"])
|
| 43 |
+
print(f" {len(idx):,} clips indexed", flush=True)
|
| 44 |
+
|
| 45 |
+
print("loading OpenVidHD.csv ...", flush=True)
|
| 46 |
+
hd = set()
|
| 47 |
+
with open(os.path.join(META, "OpenVidHD.csv"), newline="") as f:
|
| 48 |
+
for r in csv.DictReader(f):
|
| 49 |
+
hd.add(r["video"])
|
| 50 |
+
print(f" {len(hd):,} HD clips", flush=True)
|
| 51 |
+
|
| 52 |
+
print("scanning OpenVid-1M.csv ...", flush=True)
|
| 53 |
+
rows = []
|
| 54 |
+
stats = dict(total=0, prefix=0, short=0, motion=0, aesth=0, talking=0, noidx=0, bad=0)
|
| 55 |
+
with open(os.path.join(META, "OpenVid-1M.csv"), newline="") as f:
|
| 56 |
+
for r in csv.DictReader(f):
|
| 57 |
+
stats["total"] += 1
|
| 58 |
+
try:
|
| 59 |
+
v = r["video"]
|
| 60 |
+
if v.startswith(("celebv_", "pixabay_")): # 512x512 face crops / 2.67s stock
|
| 61 |
+
stats["prefix"] += 1; continue
|
| 62 |
+
sec, mot = float(r["seconds"]), float(r["motion score"])
|
| 63 |
+
nw = n_windows(sec)
|
| 64 |
+
if nw == 0:
|
| 65 |
+
stats["short"] += 1; continue
|
| 66 |
+
if not (args.motion_lo <= mot <= args.motion_hi):
|
| 67 |
+
stats["motion"] += 1; continue
|
| 68 |
+
if float(r["aesthetic score"]) < args.min_aesthetic:
|
| 69 |
+
stats["aesth"] += 1; continue
|
| 70 |
+
if not args.keep_talking and TALKING.search(r["caption"]):
|
| 71 |
+
stats["talking"] += 1; continue
|
| 72 |
+
if v not in idx:
|
| 73 |
+
stats["noidx"] += 1; continue
|
| 74 |
+
part, member, nbytes = idx[v]
|
| 75 |
+
rows.append(dict(video=v, part=part, member=member, bytes=nbytes,
|
| 76 |
+
windows=nw, seconds=sec, fps=float(r["fps"]), motion=mot,
|
| 77 |
+
aesthetic=float(r["aesthetic score"]),
|
| 78 |
+
camera=r["camera motion"], hd=int(v in hd),
|
| 79 |
+
caption=r["caption"]))
|
| 80 |
+
except Exception:
|
| 81 |
+
stats["bad"] += 1
|
| 82 |
+
|
| 83 |
+
print(json.dumps(stats, indent=2), flush=True)
|
| 84 |
+
print(f"kept: {len(rows):,} clips", flush=True)
|
| 85 |
+
|
| 86 |
+
# Sort order == download priority: any prefix of the manifest is a usable dataset.
|
| 87 |
+
if args.order == "efficiency": # most sequences per downloaded GB
|
| 88 |
+
rows.sort(key=lambda d: d["bytes"] / d["windows"])
|
| 89 |
+
elif args.order == "shuffle": # unbiased sample at any cut point
|
| 90 |
+
rows.sort(key=lambda d: hashlib.md5(("openvid" + d["video"]).encode()).hexdigest())
|
| 91 |
+
else:
|
| 92 |
+
rows.sort(key=lambda d: -(d["aesthetic"] + 2*d["hd"] - abs(d["motion"] - 12)/20))
|
| 93 |
+
|
| 94 |
+
cum = 0
|
| 95 |
+
fields = ["rank","video","part","member","bytes","cum_gb","windows",
|
| 96 |
+
"seconds","fps","motion","aesthetic","camera","hd","caption"]
|
| 97 |
+
with open(args.out, "w", newline="") as f:
|
| 98 |
+
w = csv.DictWriter(f, fieldnames=fields)
|
| 99 |
+
w.writeheader()
|
| 100 |
+
for i, d in enumerate(rows):
|
| 101 |
+
cum += d["bytes"]
|
| 102 |
+
w.writerow({"rank": i, "cum_gb": round(cum/1e9, 4), **d})
|
| 103 |
+
|
| 104 |
+
tot = sum(d["windows"] for d in rows)
|
| 105 |
+
print(f"\nmanifest -> {args.out}", flush=True)
|
| 106 |
+
print(f" {args.n_frames} frames x {args.step}s (span {SPAN}s), <= {args.max_windows} windows/clip, "
|
| 107 |
+
f"motion in [{args.motion_lo}, {args.motion_hi}]", flush=True)
|
| 108 |
+
print(f" order={args.order} {len(rows):,} clips / {tot:,} sequences / "
|
| 109 |
+
f"{tot*(args.n_frames-1):,} pairs / {cum/1e9:,.1f} GB", flush=True)
|
| 110 |
+
for b in (200, 400, 600, 800, 1000):
|
| 111 |
+
c = s = 0; acc = 0
|
| 112 |
+
for d in rows:
|
| 113 |
+
acc += d["bytes"]
|
| 114 |
+
if acc/1e9 > b: break
|
| 115 |
+
c += 1; s += d["windows"]
|
| 116 |
+
print(f" budget {b:>5} GB -> {c:>7,} clips / {s:>7,} seq / {s*(args.n_frames-1):>9,} pairs", flush=True)
|
scripts/verify_dataset.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse, collections, json, os, random, statistics
|
| 2 |
+
|
| 3 |
+
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 4 |
+
ap = argparse.ArgumentParser()
|
| 5 |
+
ap.add_argument("jsonl", nargs="?", default=os.path.join(ROOT, "sequences.jsonl"))
|
| 6 |
+
ap.add_argument("--full", action="store_true", help="stat every frame path (else sample 2000 seqs)")
|
| 7 |
+
ap.add_argument("--max-windows", type=int, default=2)
|
| 8 |
+
ap.add_argument("--motion-lo", type=float, default=5.27)
|
| 9 |
+
A = ap.parse_args()
|
| 10 |
+
|
| 11 |
+
seqs = nframes = 0
|
| 12 |
+
bad, ids = [], set()
|
| 13 |
+
per_video = collections.Counter()
|
| 14 |
+
nf_seen, step_seen = collections.Counter(), collections.Counter()
|
| 15 |
+
motions, sample = [], []
|
| 16 |
+
|
| 17 |
+
for line in open(A.jsonl):
|
| 18 |
+
d = json.loads(line)
|
| 19 |
+
seqs += 1
|
| 20 |
+
ids.add(d["id"])
|
| 21 |
+
per_video[d["video"]] += 1
|
| 22 |
+
nf_seen[d["n_frames"]] += 1
|
| 23 |
+
step_seen[d["step_sec"]] += 1
|
| 24 |
+
motions.append(float(d["meta"]["motion"]))
|
| 25 |
+
fr = d["frames"]
|
| 26 |
+
nframes += len(fr)
|
| 27 |
+
if len(fr) != d["n_frames"] or len(d["timestamps"]) != len(fr):
|
| 28 |
+
bad.append((d["id"], "len mismatch"))
|
| 29 |
+
ts = d["timestamps"]
|
| 30 |
+
if any(round(ts[i+1] - ts[i], 3) != d["step_sec"] for i in range(len(ts)-1)):
|
| 31 |
+
bad.append((d["id"], "irregular timestamps"))
|
| 32 |
+
if A.full:
|
| 33 |
+
for p in fr:
|
| 34 |
+
if not os.path.exists(os.path.join(ROOT, p)):
|
| 35 |
+
bad.append((d["id"], f"missing {p}")); break
|
| 36 |
+
else:
|
| 37 |
+
sample.append((d["id"], fr))
|
| 38 |
+
|
| 39 |
+
if not A.full and sample:
|
| 40 |
+
for sid, fr in random.Random(0).sample(sample, min(2000, len(sample))):
|
| 41 |
+
for p in fr:
|
| 42 |
+
if not os.path.exists(os.path.join(ROOT, p)):
|
| 43 |
+
bad.append((sid, f"missing {p}")); break
|
| 44 |
+
|
| 45 |
+
over = [v for v, c in per_video.items() if c > A.max_windows]
|
| 46 |
+
low = [m for m in motions if m < A.motion_lo]
|
| 47 |
+
|
| 48 |
+
print(f"sequences : {seqs:,}")
|
| 49 |
+
print(f"unique ids : {len(ids):,} (dupes: {seqs - len(ids)})")
|
| 50 |
+
print(f"source clips : {len(per_video):,} (mean {seqs/max(1,len(per_video)):.2f} windows/clip)")
|
| 51 |
+
print(f"windows/clip : {dict(sorted(collections.Counter(per_video.values()).items()))}"
|
| 52 |
+
f" over cap({A.max_windows}): {len(over)}")
|
| 53 |
+
print(f"n_frames : {dict(nf_seen)}")
|
| 54 |
+
print(f"step_sec : {dict(step_seen)}")
|
| 55 |
+
print(f"frames listed : {nframes:,}")
|
| 56 |
+
print(f"adjacent pairs : {nframes - seqs:,} <- VLM caption calls")
|
| 57 |
+
if motions:
|
| 58 |
+
ms = sorted(motions)
|
| 59 |
+
print(f"motion : min {ms[0]:.2f} med {statistics.median(ms):.2f} "
|
| 60 |
+
f"max {ms[-1]:.2f} below {A.motion_lo}: {len(low)}")
|
| 61 |
+
print(f"path check : {'FULL' if A.full else f'sampled {min(2000,len(sample))} seqs'} "
|
| 62 |
+
f"-> {len(bad)} problems")
|
| 63 |
+
for b in bad[:10]:
|
| 64 |
+
print(" ", b)
|
| 65 |
+
|
| 66 |
+
fs = []
|
| 67 |
+
for dp, _, fn in os.walk(os.path.join(ROOT, "frames")):
|
| 68 |
+
fs += [os.path.getsize(os.path.join(dp, f)) for f in fn if f.endswith(".jpg")]
|
| 69 |
+
if fs:
|
| 70 |
+
print(f"jpgs on disk : {len(fs):,} ({sum(fs)/1e9:.1f} GB, mean {statistics.mean(fs)/1024:.0f} KB)")
|
| 71 |
+
print(f"orphan jpgs : {len(fs) - nframes:,}")
|
| 72 |
+
vd = os.path.join(ROOT, "videos")
|
| 73 |
+
vids = [os.path.getsize(os.path.join(vd, f)) for f in os.listdir(vd) if f.endswith(".mp4")]
|
| 74 |
+
print(f"videos on disk : {len(vids):,} ({sum(vids)/1e9:.1f} GB)")
|