Spaces:
Runtime error
Runtime error
File size: 1,117 Bytes
40e0b51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | """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()
|