""" Download a small sample of UVH-26 validation images (Bengaluru Safe-City CCTV, CC BY 4.0) plus their COCO annotations for qualitative and vehicle-detection evaluation. Usage: python tools/fetch_uvh_samples.py --n 60 Output: ext_data/uvh26_val_sample/images/*.png and annotations.json (subset) """ from __future__ import annotations import argparse import json import os import random import shutil from pathlib import Path os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1") os.environ.setdefault("HF_HUB_DISABLE_SYMLINKS_WARNING", "1") from huggingface_hub import HfApi, hf_hub_download # noqa: E402 ROOT = Path(__file__).resolve().parent.parent OUT = ROOT / "ext_data" / "uvh26_val_sample" REPO = "iisc-aim/UVH-26" def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--n", type=int, default=60) parser.add_argument("--seed", type=int, default=26) args = parser.parse_args() (OUT / "images").mkdir(parents=True, exist_ok=True) ann_path = hf_hub_download(REPO, "UVH-26-Val/UVH-26-MV-Val.json", repo_type="dataset") coco = json.loads(Path(ann_path).read_text()) api = HfApi() files = [f for f in api.list_repo_files(REPO, repo_type="dataset") if f.startswith("UVH-26-Val/data/")] random.Random(args.seed).shuffle(files) chosen = files[: args.n] by_name = {Path(img["file_name"]).name: img for img in coco["images"]} keep_images = [] for f in chosen: local = hf_hub_download(REPO, f, repo_type="dataset") dst = OUT / "images" / Path(f).name shutil.copy(local, dst) if Path(f).name in by_name: keep_images.append(by_name[Path(f).name]) print("got", dst.name, flush=True) ids = {img["id"] for img in keep_images} subset = { "images": keep_images, "annotations": [a for a in coco["annotations"] if a["image_id"] in ids], "categories": coco["categories"], } (OUT / "annotations.json").write_text(json.dumps(subset)) print(f"saved {len(keep_images)} images with {len(subset['annotations'])} boxes") if __name__ == "__main__": main()