Datasets:
Download scripts/copy_metadata.py from hotsightdataset/HotSight: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/datasets/hotsightdataset/HotSight/resolve/main/scripts/copy_metadata.py
- Command line
-
hf download hf://datasets/hotsightdataset/HotSight/scripts/copy_metadata.py
-
curl -L -o copy_metadata.py https://huggingface.co/datasets/hotsightdataset/HotSight/resolve/main/scripts/copy_metadata.py
1.62 kB
| #!/usr/bin/env python3 | |
| """Copy masks and homographies into a reproduced dataset.""" | |
| import argparse | |
| import shutil | |
| from pathlib import Path | |
| def copy_annotations(source_root, destination_root): | |
| copied = 0 | |
| for unit_dir in sorted(path for path in destination_root.iterdir() if path.is_dir()): | |
| for pair_dir in sorted(path for path in unit_dir.iterdir() if path.is_dir()): | |
| source_pair = source_root / unit_dir.name / pair_dir.name | |
| for name in ("mask", "homography"): | |
| source = source_pair / name | |
| if not source.is_dir(): | |
| raise RuntimeError(f"missing annotation directory: {source}") | |
| shutil.copytree(source, pair_dir / name, dirs_exist_ok=True) | |
| copied += 1 | |
| print(f"Copied {copied} directories to {destination_root}") | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "destination", | |
| type=Path, | |
| nargs="?", | |
| default=Path("Data"), | |
| help="reproduced dataset root (default: Data/)", | |
| ) | |
| parser.add_argument( | |
| "--source", | |
| type=Path, | |
| default=Path("AnnotationHomography"), | |
| help="annotation root (default: AnnotationHomography/)", | |
| ) | |
| args = parser.parse_args() | |
| if not args.source.is_dir(): | |
| parser.error(f"source directory does not exist: {args.source}") | |
| if not args.destination.is_dir(): | |
| parser.error(f"destination directory does not exist: {args.destination}") | |
| copy_annotations(args.source, args.destination) | |
| if __name__ == "__main__": | |
| main() | |