Spaces:
Sleeping
Sleeping
| """ | |
| run_detection.py — CLI entrypoint for the OWLv2 detection stage. | |
| Usage: | |
| uv run python scripts/run_detection.py --image-dir data/raw --output-dir data/detections | |
| uv run python scripts/run_detection.py --help | |
| """ | |
| from __future__ import annotations | |
| import logging | |
| from pathlib import Path | |
| from typing import Optional | |
| import click | |
| from dotenv import load_dotenv | |
| load_dotenv() # picks up PYTORCH_ENABLE_MPS_FALLBACK and other vars | |
| from autolabel.detect import run_detection | |
| from autolabel.config import settings | |
| from autolabel.utils import setup_logging | |
| def main( | |
| image_dir: Path, | |
| output_dir: Path, | |
| prompts: Optional[str], | |
| threshold: Optional[float], | |
| force: bool, | |
| verbose: bool, | |
| ) -> None: | |
| """Run OWLv2 open-vocabulary detection on IMAGE_DIR images.""" | |
| setup_logging(logging.DEBUG if verbose else logging.INFO) | |
| prompt_list = None | |
| if prompts: | |
| prompt_list = [p.strip() for p in prompts.split(",") if p.strip()] | |
| if threshold is not None: | |
| settings.threshold = threshold | |
| run_detection( | |
| image_dir=image_dir, | |
| output_dir=output_dir, | |
| prompts=prompt_list, | |
| cfg=settings, | |
| force=force, | |
| ) | |
| if __name__ == "__main__": | |
| main() |