Datasets:
Upload extract_images.py with huggingface_hub
Browse files- extract_images.py +41 -0
extract_images.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extract SoloFace2 image archives.
|
| 2 |
+
|
| 3 |
+
Download all images_part_*.tar.gz files to this directory and run:
|
| 4 |
+
python extract_images.py
|
| 5 |
+
|
| 6 |
+
This will extract all 311,717 images into the images/ directory.
|
| 7 |
+
Already-extracted images are skipped (safe to re-run).
|
| 8 |
+
"""
|
| 9 |
+
import tarfile, sys, os
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
ARCHIVE_PREFIX = 'images_part_'
|
| 13 |
+
OUTPUT_DIR = Path(__file__).parent / 'images'
|
| 14 |
+
OUTPUT_DIR.mkdir(exist_ok=True)
|
| 15 |
+
|
| 16 |
+
# Find all archive files
|
| 17 |
+
archives = sorted(Path(__file__).parent.glob(f'{ARCHIVE_PREFIX}*.tar.gz'))
|
| 18 |
+
if not archives:
|
| 19 |
+
print('ERROR: No images_part_*.tar.gz files found!')
|
| 20 |
+
print('Download all archive files to this directory first.')
|
| 21 |
+
sys.exit(1)
|
| 22 |
+
|
| 23 |
+
print(f'Found {len(archives)} archive(s):')
|
| 24 |
+
for a in archives:
|
| 25 |
+
print(f' {a.name} ({a.stat().st_size / 1e6:.0f} MB)')
|
| 26 |
+
|
| 27 |
+
total_extracted = 0
|
| 28 |
+
for archive in archives:
|
| 29 |
+
print(f'\nExtracting {archive.name}...')
|
| 30 |
+
with tarfile.open(archive, 'r:gz') as tar:
|
| 31 |
+
members = tar.getmembers()
|
| 32 |
+
for i, member in enumerate(members):
|
| 33 |
+
target = OUTPUT_DIR / member.name.split('/')[-1]
|
| 34 |
+
if target.exists():
|
| 35 |
+
continue # Skip already-extracted
|
| 36 |
+
tar.extract(member, path=OUTPUT_DIR.parent, filter='data')
|
| 37 |
+
if (i + 1) % 10000 == 0:
|
| 38 |
+
print(f' {i+1:,}/{len(members):,}')
|
| 39 |
+
total_extracted += len(members)
|
| 40 |
+
|
| 41 |
+
print(f'\nDone! {total_extracted:,} images in {OUTPUT_DIR}/')
|