Buckets:
| """ | |
| Create a new dataset similar to Subject2Video-Dataset but using two reference image sources: | |
| - 50% from ref_imgs_masked/person (videos sourced from videos/videos/) | |
| - 50% from reference_images/head (videos sourced from Subject2Video-Dataset/) | |
| Each video has exactly one reference image. | |
| Since person pool has 1091 videos and head pool has 2997, we use all 1091 person videos | |
| and randomly sample 1091 head videos for a balanced 50/50 split (2182 total). | |
| """ | |
| import os | |
| import random | |
| import shutil | |
| from pathlib import Path | |
| BASE = Path("/mnt/data/xinyuy/datasets/ConsisID-preview-Data") | |
| PERSON_REFS = BASE / "ref_imgs_masked" / "person" | |
| PERSON_VIDEOS = BASE / "videos" / "videos" | |
| HEAD_REFS = BASE / "reference_images" / "head" | |
| HEAD_VIDEOS = BASE / "Subject2Video-Dataset" | |
| OUT_DIR = BASE / "Subject2Video-Dataset-MaskedRef" | |
| SEED = 42 | |
| random.seed(SEED) | |
| # --- Person pool: all 1091 videos with masked person references --- | |
| person_stems = sorted(f[:-4] for f in os.listdir(PERSON_REFS) if f.endswith(".jpg")) | |
| assert all((PERSON_VIDEOS / f"{s}.mp4").exists() for s in person_stems), \ | |
| "Some person stems missing from videos/videos" | |
| # --- Head pool: all 2997 videos with head references, sample 1091 --- | |
| head_stems_all = sorted(f[:-4] for f in os.listdir(HEAD_REFS) if f.endswith(".jpg")) | |
| assert all((HEAD_VIDEOS / f"{s}.mp4").exists() for s in head_stems_all), \ | |
| "Some head stems missing from Subject2Video-Dataset" | |
| random.shuffle(head_stems_all) | |
| head_stems = head_stems_all[:len(person_stems)] # sample to match person count | |
| print(f"Person pool (all): {len(person_stems)}") | |
| print(f"Head pool (sampled): {len(head_stems)}") | |
| print(f"Total: {len(person_stems) + len(head_stems)}") | |
| # Remove old output and recreate | |
| if OUT_DIR.exists(): | |
| shutil.rmtree(OUT_DIR) | |
| OUT_DIR.mkdir() | |
| # Write person entries | |
| for stem in person_stems: | |
| src_video = PERSON_VIDEOS / f"{stem}.mp4" | |
| dst_video = OUT_DIR / f"{stem}.mp4" | |
| os.symlink(src_video, dst_video) | |
| src_ref = PERSON_REFS / f"{stem}.jpg" | |
| shutil.copy2(src_ref, OUT_DIR / f"{stem}_reference.jpg") | |
| # Write head entries | |
| for stem in head_stems: | |
| src_video = HEAD_VIDEOS / f"{stem}.mp4" | |
| dst_video = OUT_DIR / f"{stem}.mp4" | |
| os.symlink(src_video, dst_video) | |
| src_ref = HEAD_REFS / f"{stem}.jpg" | |
| shutil.copy2(src_ref, OUT_DIR / f"{stem}_reference.jpg") | |
| total = len(list(OUT_DIR.iterdir())) | |
| n_mp4 = sum(1 for f in OUT_DIR.iterdir() if f.suffix == ".mp4") | |
| n_ref = sum(1 for f in OUT_DIR.iterdir() if f.name.endswith("_reference.jpg")) | |
| print(f"\nDone. Output: {OUT_DIR}") | |
| print(f"Total files: {total}") | |
| print(f" Videos: {n_mp4}") | |
| print(f" References: {n_ref}") | |
Xet Storage Details
- Size:
- 2.69 kB
- Xet hash:
- 4372f483f22f72524fc0c3e31eef3ce637ce88cac3143026edfcbb504fb4373a
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.