DesignVFR / unpack.py
Tunanzzz's picture
docs: replace placeholder repo-id in unpack.py docstring
c57a913 verified
Raw
History Blame Contribute Delete
1.4 kB
# Auto-generated by pack_for_huggingface.py
"""One-line unpacker for the DesignVFR HuggingFace release.
After ``huggingface-cli download Tunanzzz/DesignVFR --repo-type dataset``,
run::
python unpack.py
It will extract every ``*.tar`` / ``*.part-XXX.tar`` next to itself in-place
so that the directory layout matches the paths inside the metadata
jsonl/json (which are anchored on ``${DATASET_ROOT}``).
"""
from __future__ import annotations
import sys
import tarfile
from pathlib import Path
def main():
root = Path(__file__).resolve().parent
tars = sorted(root.rglob('*.tar'))
if not tars:
print('No .tar files found under', root)
return
print(f'Found {len(tars)} tar shard(s) under {root}')
for t in tars:
# Each tar is anchored on its parent directory's "image root" -- e.g.
# synthetic/train.part-001.tar -> extract into synthetic/train/
# synthetic/ood_infer.tar -> extract into synthetic/ood_infer/
stem = t.name.split('.', 1)[0] # "train.part-001.tar" -> "train"
dest = t.parent / stem
dest.mkdir(parents=True, exist_ok=True)
print(f' extracting {t.relative_to(root)} -> {dest.relative_to(root)}/')
with tarfile.open(t, 'r') as f:
f.extractall(dest)
print('Done. You can now `export DATASET_ROOT=' + str(root) + '`.')
if __name__ == '__main__':
main()