Download preprocess/resolve_paths.py from tsinghua-ee/ELLSA2_data: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/datasets/tsinghua-ee/ELLSA2_data/resolve/main/preprocess/resolve_paths.py
- Command line
-
hf download hf://datasets/tsinghua-ee/ELLSA2_data/preprocess/resolve_paths.py
-
curl -L -o resolve_paths.py https://huggingface.co/datasets/tsinghua-ee/ELLSA2_data/resolve/main/preprocess/resolve_paths.py
1.44 kB
| """Resolve the portable training manifest against downloaded source data.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| def resolve_paths(value, dataset_root, flame_root=None): | |
| roots = [("data/source/seamless_interaction/", Path(dataset_root).resolve()), | |
| ("data/source/flame/", Path(flame_root).resolve() if flame_root else None)] | |
| def resolve(x): | |
| if isinstance(x, dict): | |
| return {k: resolve(v) for k, v in x.items()} | |
| if isinstance(x, list): | |
| return [resolve(v) for v in x] | |
| if isinstance(x, str): | |
| for prefix, root in roots: | |
| if x.startswith(prefix): | |
| assert root, f"Provide a source root for {prefix}" | |
| return str(root / x[len(prefix):]) | |
| return x | |
| return resolve(value) | |
| def main(): | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--input", default=str(Path(__file__).resolve().parents[1] / "manifests/train_selected81.json")) | |
| p.add_argument("--dataset-root", required=True) | |
| p.add_argument("--flame-root", help="Root for optional data/source/flame/ entries") | |
| p.add_argument("--output", required=True) | |
| a = p.parse_args() | |
| output = Path(a.output) | |
| output.parent.mkdir(parents=True, exist_ok=True) | |
| output.write_text(json.dumps(resolve_paths(json.loads(Path(a.input).read_text()), a.dataset_root, a.flame_root), indent=2)) | |
| if __name__ == "__main__": | |
| main() | |