Only create colormap for enabled labels

This commit is contained in:
Nick Mowen 2023-01-06 12:29:40 -07:00
parent 417a42b0b3
commit 2185456ea5
2 changed files with 13 additions and 4 deletions

View File

@ -962,6 +962,12 @@ class FrigateConfig(FrigateBaseModel):
camera_config.create_ffmpeg_cmds() camera_config.create_ffmpeg_cmds()
config.cameras[name] = camera_config config.cameras[name] = camera_config
# get list of unique enabled labels for tracking
enabled_labels = set(config.objects.track)
for _, camera in config.cameras.items():
enabled_labels.update(camera.objects.track)
for key, detector in config.detectors.items(): for key, detector in config.detectors.items():
detector_config: DetectorConfig = parse_obj_as(DetectorConfig, detector) detector_config: DetectorConfig = parse_obj_as(DetectorConfig, detector)
if detector_config.model is None: if detector_config.model is None:
@ -986,6 +992,7 @@ class FrigateConfig(FrigateBaseModel):
config.model.dict(exclude_unset=True), config.model.dict(exclude_unset=True),
) )
detector_config.model = ModelConfig.parse_obj(merged_model) detector_config.model = ModelConfig.parse_obj(merged_model)
detector_config.model.create_colormap(enabled_labels)
config.detectors[key] = detector_config config.detectors[key] = detector_config
return config return config

View File

@ -55,11 +55,13 @@ class ModelConfig(BaseModel):
**load_labels(config.get("labelmap_path", "/labelmap.txt")), **load_labels(config.get("labelmap_path", "/labelmap.txt")),
**config.get("labelmap", {}), **config.get("labelmap", {}),
} }
cmap = plt.cm.get_cmap("tab10", len(self._merged_labelmap.keys()))
self._colormap = {} self._colormap = {}
for key, val in self._merged_labelmap.items():
def create_colormap(self, enabled_labels: set[str]) -> None:
"""Get a list of colors for enabled labels."""
cmap = plt.cm.get_cmap("tab10", len(enabled_labels))
for key, val in enumerate(enabled_labels):
self._colormap[val] = tuple(int(round(255 * c)) for c in cmap(key)[:3]) self._colormap[val] = tuple(int(round(255 * c)) for c in cmap(key)[:3])
class Config: class Config: