Download scripts/load_armbench_vl.py from ChrisDing1105/ARMBench-VL: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/ChrisDing1105/ARMBench-VL/resolve/main/scripts/load_armbench_vl.py
- Command line
-
hf download hf://datasets/ChrisDing1105/ARMBench-VL/scripts/load_armbench_vl.py
-
curl -L -o load_armbench_vl.py https://huggingface.co/datasets/ChrisDing1105/ARMBench-VL/resolve/main/scripts/load_armbench_vl.py
2.1 kB
| """Small dependency-free loader for a downloaded ARMBench-VL release.""" | |
| from __future__ import annotations | |
| import json | |
| import re | |
| from pathlib import Path | |
| from typing import Any, Iterator | |
| def _config(root: Path) -> dict[str, dict[str, Any]]: | |
| return json.loads((root / "dataset_config.json").read_text(encoding="utf-8")) | |
| def load_records(root: str | Path, task: str) -> list[dict[str, Any]]: | |
| root = Path(root) | |
| task_config = _config(root)[task] | |
| annotation_path = root / task_config["annotations"] | |
| with annotation_path.open(encoding="utf-8") as handle: | |
| return [json.loads(line) for line in handle if line.strip()] | |
| def resolve_images( | |
| root: str | Path, task: str, record: dict[str, Any] | |
| ) -> list[Path]: | |
| root = Path(root) | |
| resource_root = root / _config(root)[task]["resource_root"] | |
| return [resource_root / image for image in record.get("images", [])] | |
| def iter_document_pages(root: str | Path, doc_id: str) -> Iterator[Path]: | |
| """Yield individual page images in numeric order, excluding composites.""" | |
| root = Path(root) | |
| resource_root = root / _config(root)["multimodal_long_document_qa"][ | |
| "resource_root" | |
| ] | |
| stem = Path(doc_id).stem | |
| pattern = re.compile(rf"^{re.escape(stem)}_(\d+)\.(?:jpg|jpeg|png|webp)$", re.I) | |
| pages: list[tuple[int, Path]] = [] | |
| for path in resource_root.glob(f"{stem}_*"): | |
| match = pattern.match(path.name) | |
| if match: | |
| pages.append((int(match.group(1)), path)) | |
| for _, path in sorted(pages): | |
| yield path | |
| if __name__ == "__main__": | |
| import argparse | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("root", type=Path) | |
| parser.add_argument( | |
| "task", | |
| choices=( | |
| "fine_grained_perception", | |
| "multimodal_long_document_qa", | |
| "multimodal_instruction_following", | |
| ), | |
| ) | |
| args = parser.parse_args() | |
| records = load_records(args.root, args.task) | |
| print(f"{args.task}: {len(records)} examples") | |
| print("first image(s):", *resolve_images(args.root, args.task, records[0])) | |