Datasets:
Upload unpack_images.py with huggingface_hub
Browse files- unpack_images.py +26 -0
unpack_images.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Unpack images.tar into the images/ directory for training."""
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
root = Path(__file__).parent.resolve()
|
| 9 |
+
tar_file = root / "images.tar"
|
| 10 |
+
if not tar_file.exists():
|
| 11 |
+
print(f"Error: {tar_file} not found.", file=sys.stderr)
|
| 12 |
+
return 1
|
| 13 |
+
|
| 14 |
+
out_dir = root / "images"
|
| 15 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 16 |
+
print(f"Extracting {tar_file} into {root}...")
|
| 17 |
+
res = subprocess.run(["tar", "-xf", str(tar_file), "-C", str(root)])
|
| 18 |
+
if res.returncode == 0:
|
| 19 |
+
print("Extraction complete! Images are ready in ./images/")
|
| 20 |
+
return 0
|
| 21 |
+
else:
|
| 22 |
+
print("Failed to extract images.", file=sys.stderr)
|
| 23 |
+
return res.returncode
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
sys.exit(main())
|