File size: 2,241 Bytes
13170f7
 
 
 
 
 
0cb83bc
 
 
 
86778a6
 
 
13170f7
 
 
 
86778a6
13170f7
 
 
 
86778a6
 
 
13170f7
 
86778a6
13170f7
 
 
 
 
86778a6
13170f7
 
 
86778a6
13170f7
 
 
 
 
 
 
 
 
 
 
0cb83bc
 
 
86778a6
 
 
 
13170f7
0cb83bc
 
86778a6
 
 
 
13170f7
 
 
 
 
0cb83bc
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""MOD model registry for the eve_gmod demo.

This is the single place that maps each selectable model name to the
``ModelConfig`` the EVE worker loads. Adding a model, or pointing an existing
one at new weights, is a one-line change here — nothing else needs to move.

- **GMOD Base Model** uses the EVE SDK's bundled default model, so it carries
  no path and no class table.
- **Automotive Object Detector** and **Office Object Detector** load their
  ``.tflite`` from ``MOD_MODELS_DIR``
  (the gated weights fetched at build time, see ``install_eve.py``; falls back to
  the demo-relative ``models/`` locally) and ship their own class labels (in
  output-index order).
"""

from __future__ import annotations

import os
from pathlib import Path

from eve_messages import ModelConfig

# In the Space the gated weights are fetched to MOD_MODELS_DIR by install_eve.py
# at Docker build time; local runs fall back to the demo-relative ``models/``.
_MODELS_DIR = Path(os.environ.get("MOD_MODELS_DIR") or Path(__file__).resolve().parent / "models")

# Class labels in the order the model emits them (output index -> label).
AUTOMOTIVE_CLASS_NAMES: tuple[str, ...] = (
    "person",
    "bicycle",
    "car",
    "motorcycle",
    "bus",
    "truck",
    "traffic light",
    "stop sign",
)
OFFICE_CLASS_NAMES: tuple[str, ...] = (
    "bottle",
    "cup",
    "potted plant",
    "laptop",
    "mouse",
    "keyboard",
    "cell phone",
    "book",
)

MOD_MODEL_REGISTRY: dict[str, ModelConfig] = {
    "GMOD Base Model": ModelConfig(name="GMOD Base Model", nms_threshold=0.2),
    "Automotive Object Detector": ModelConfig(
        name="Automotive Object Detector",
        model_path=str(_MODELS_DIR / "automotive-640x640.tflite"),
        class_names=AUTOMOTIVE_CLASS_NAMES,
        nms_threshold=0.4,
        iou_threshold=0.4
    ),
    "Office Object Detector": ModelConfig(
        name="Office Object Detector",
        model_path=str(_MODELS_DIR / "office-640x640.tflite"),
        class_names=OFFICE_CLASS_NAMES,
        nms_threshold=0.4,
        iou_threshold=0.4
    ),
}

# UI order of the selection radio; first entry is the default.
MOD_MODELS: list[str] = list(MOD_MODEL_REGISTRY)
DEFAULT_MOD_MODEL: str = "GMOD Base Model"