Spaces:
Runtime error
Runtime error
Download scripts/inspect_model.py from openscopelabs/cctv-object-detection: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/openscopelabs/cctv-object-detection/resolve/main/scripts/inspect_model.py
- Command line
-
hf download hf://spaces/openscopelabs/cctv-object-detection/scripts/inspect_model.py
-
curl -L -o inspect_model.py https://huggingface.co/spaces/openscopelabs/cctv-object-detection/resolve/main/scripts/inspect_model.py
1.12 kB
| """Print the class names of a YOLO .pt model file. | |
| Useful after downloading a Roboflow / Hugging Face / custom-trained | |
| model — run this to see what class names it exposes, then update | |
| ``VEHICLE_CLASS_NAMES`` / ``PERSON_CLASS_NAMES`` in `.env` to include | |
| any names you want counted. | |
| Usage: | |
| .venv/bin/python -m scripts.inspect_model models/your-model.pt | |
| """ | |
| from __future__ import annotations | |
| import sys | |
| from pathlib import Path | |
| from ultralytics import YOLO | |
| def main() -> None: | |
| if len(sys.argv) < 2: | |
| print("usage: python -m scripts.inspect_model <path-to-.pt>", file=sys.stderr) | |
| sys.exit(1) | |
| path = sys.argv[1] | |
| if not Path(path).exists() and not path.startswith(("yolov", "yolo")): | |
| print(f"file not found: {path}", file=sys.stderr) | |
| sys.exit(2) | |
| m = YOLO(path) | |
| names = dict(getattr(m, "names", {}) or {}) | |
| print(f"model: {path}") | |
| print(f"classes: {len(names)}") | |
| print() | |
| print(f"{'id':>4} name") | |
| print(f"{'-'*4} {'-'*30}") | |
| for cid in sorted(names): | |
| print(f"{cid:>4} {names[cid]}") | |
| if __name__ == "__main__": | |
| main() | |