File size: 2,368 Bytes
de254b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | """Link only files referenced by the selected training manifest into the data package."""
import argparse
import json
from pathlib import Path
DATA_ROOT = Path(__file__).resolve().parents[1]
PREFIX = 'data/source/seamless_interaction/'
FIELDS = ('pose_file', 'audio_file', 'audio_file_listen', 'word_file', 'flame_file')
def link_training_data(manifest, dataset_root, data_root, flame_root=None):
dataset_root, data_root = Path(dataset_root).resolve(), Path(data_root).resolve()
rows = json.loads(Path(manifest).read_text())['data']
sources = {}
for row in rows:
for field in FIELDS:
path = row[field]
assert path.startswith(PREFIX), f'Unexpected {field} path: {path}'
name = Path(path[len(PREFIX):])
assert not name.is_absolute() and '..' not in name.parts, name
source = (Path(flame_root).resolve() / name.name
if field == 'flame_file' and flame_root else dataset_root / name)
assert name not in sources or sources[name] == source, name
sources[name] = source
for source in sources.values():
assert source.is_file(), source
for name, source in sorted(sources.items()):
destination = data_root / 'source/seamless_interaction' / name
if destination.is_symlink():
assert destination.resolve() == source.resolve(), destination
else:
assert not destination.exists(), destination
destination.parent.mkdir(parents=True, exist_ok=True)
destination.symlink_to(source)
return len(sources)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--input', default=str(DATA_ROOT / 'manifests/train_selected81.json'))
parser.add_argument('--dataset-root', required=True, help='Downloaded Seamless Interaction root')
parser.add_argument('--flame-root', help='Directory of freshly extracted <pose_stem>_flame.npz labels')
parser.add_argument('--data-root', default=str(DATA_ROOT), help='Data package receiving source links')
args = parser.parse_args()
count = link_training_data(args.input, args.dataset_root, args.data_root, args.flame_root)
print(f'Linked {count} unique training files under {Path(args.data_root) / "source/seamless_interaction"}')
if __name__ == '__main__':
main()
|