mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-07 23:32:48 +03:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4d8b832f5 | ||
|
|
148b2fc0c5 |
@@ -13,6 +13,6 @@ nvidia-cusolver-cu12==11.7.3.90; platform_machine == 'x86_64'
|
|||||||
nvidia-cusparse-cu12==12.5.8.93; platform_machine == 'x86_64'
|
nvidia-cusparse-cu12==12.5.8.93; platform_machine == 'x86_64'
|
||||||
nvidia-nccl-cu12==2.26.2.post1; platform_machine == 'x86_64'
|
nvidia-nccl-cu12==2.26.2.post1; platform_machine == 'x86_64'
|
||||||
nvidia-nvjitlink-cu12==12.8.93; platform_machine == 'x86_64'
|
nvidia-nvjitlink-cu12==12.8.93; platform_machine == 'x86_64'
|
||||||
onnx==1.16.*; platform_machine == 'x86_64'
|
onnx==1.22.*; platform_machine == 'x86_64'
|
||||||
onnxruntime-gpu==1.24.*; platform_machine == 'x86_64'
|
onnxruntime-gpu==1.24.*; platform_machine == 'x86_64'
|
||||||
protobuf==3.20.3; platform_machine == 'x86_64'
|
protobuf==3.20.3; platform_machine == 'x86_64'
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
onnx == 1.14.0; platform_machine == 'aarch64'
|
onnx == 1.22.0; platform_machine == 'aarch64'
|
||||||
protobuf == 3.20.3; platform_machine == 'aarch64'
|
protobuf == 3.20.3; platform_machine == 'aarch64'
|
||||||
|
|||||||
@@ -200,9 +200,6 @@ class EmbeddingMaintainer(threading.Thread):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for model_config in self.config.classification.custom.values():
|
for model_config in self.config.classification.custom.values():
|
||||||
if not model_config.enabled:
|
|
||||||
continue
|
|
||||||
|
|
||||||
self.realtime_processors.append(
|
self.realtime_processors.append(
|
||||||
CustomStateClassificationProcessor(
|
CustomStateClassificationProcessor(
|
||||||
self.config, model_config, self.requestor, self.metrics
|
self.config, model_config, self.requestor, self.metrics
|
||||||
@@ -335,25 +332,6 @@ class EmbeddingMaintainer(threading.Thread):
|
|||||||
for processor in self.post_processors:
|
for processor in self.post_processors:
|
||||||
processor.update_config(topic, payload)
|
processor.update_config(topic, payload)
|
||||||
|
|
||||||
def _remove_custom_classification_processor(self, model_name: str) -> None:
|
|
||||||
"""Shut down and drop any running processor for a custom model."""
|
|
||||||
remaining = []
|
|
||||||
for processor in self.realtime_processors:
|
|
||||||
if (
|
|
||||||
isinstance(
|
|
||||||
processor,
|
|
||||||
(
|
|
||||||
CustomStateClassificationProcessor,
|
|
||||||
CustomObjectClassificationProcessor,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
and processor.model_config.name == model_name
|
|
||||||
):
|
|
||||||
processor.shutdown()
|
|
||||||
else:
|
|
||||||
remaining.append(processor)
|
|
||||||
self.realtime_processors = remaining
|
|
||||||
|
|
||||||
def _handle_custom_classification_update(
|
def _handle_custom_classification_update(
|
||||||
self, topic: str, model_config: Any
|
self, topic: str, model_config: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -361,7 +339,23 @@ class EmbeddingMaintainer(threading.Thread):
|
|||||||
model_name = topic.split("/")[-1]
|
model_name = topic.split("/")[-1]
|
||||||
|
|
||||||
if model_config is None:
|
if model_config is None:
|
||||||
self._remove_custom_classification_processor(model_name)
|
remaining = []
|
||||||
|
for processor in self.realtime_processors:
|
||||||
|
if (
|
||||||
|
isinstance(
|
||||||
|
processor,
|
||||||
|
(
|
||||||
|
CustomStateClassificationProcessor,
|
||||||
|
CustomObjectClassificationProcessor,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
and processor.model_config.name == model_name
|
||||||
|
):
|
||||||
|
processor.shutdown()
|
||||||
|
else:
|
||||||
|
remaining.append(processor)
|
||||||
|
self.realtime_processors = remaining
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Successfully removed classification processor for model: {model_name}"
|
f"Successfully removed classification processor for model: {model_name}"
|
||||||
)
|
)
|
||||||
@@ -369,13 +363,6 @@ class EmbeddingMaintainer(threading.Thread):
|
|||||||
|
|
||||||
self.config.classification.custom[model_name] = model_config
|
self.config.classification.custom[model_name] = model_config
|
||||||
|
|
||||||
# A disabled model must not run; tear down any existing processor and
|
|
||||||
# do not register a new one.
|
|
||||||
if not model_config.enabled:
|
|
||||||
self._remove_custom_classification_processor(model_name)
|
|
||||||
logger.info(f"Disabled classification processor for model: {model_name}")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Check if processor already exists
|
# Check if processor already exists
|
||||||
for processor in self.realtime_processors:
|
for processor in self.realtime_processors:
|
||||||
if isinstance(
|
if isinstance(
|
||||||
@@ -715,11 +702,7 @@ class EmbeddingMaintainer(threading.Thread):
|
|||||||
and "license_plate" not in camera_config.objects.track
|
and "license_plate" not in camera_config.objects.track
|
||||||
)
|
)
|
||||||
|
|
||||||
has_enabled_custom = any(
|
if not dedicated_lpr_enabled and len(self.config.classification.custom) == 0:
|
||||||
c.enabled for c in self.config.classification.custom.values()
|
|
||||||
)
|
|
||||||
|
|
||||||
if not dedicated_lpr_enabled and not has_enabled_custom:
|
|
||||||
# no active features that use this data
|
# no active features that use this data
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
"""Tests that disabled custom classification models are not registered or run."""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import unittest
|
|
||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
# Mock TFLite before importing the maintainer / classification modules
|
|
||||||
_MOCK_MODULES = [
|
|
||||||
"tflite_runtime",
|
|
||||||
"tflite_runtime.interpreter",
|
|
||||||
"ai_edge_litert",
|
|
||||||
"ai_edge_litert.interpreter",
|
|
||||||
]
|
|
||||||
for mod in _MOCK_MODULES:
|
|
||||||
if mod not in sys.modules:
|
|
||||||
sys.modules[mod] = MagicMock()
|
|
||||||
|
|
||||||
from frigate.data_processing.real_time.custom_classification import ( # noqa: E402
|
|
||||||
CustomObjectClassificationProcessor,
|
|
||||||
)
|
|
||||||
from frigate.embeddings.maintainer import EmbeddingMaintainer # noqa: E402
|
|
||||||
|
|
||||||
|
|
||||||
class TestCustomClassificationEnabledGating(unittest.TestCase):
|
|
||||||
"""A model with enabled: false must not keep a processor registered."""
|
|
||||||
|
|
||||||
def _make_maintainer(self) -> EmbeddingMaintainer:
|
|
||||||
# Bypass the heavy __init__; only the attributes touched by the
|
|
||||||
# config update path are needed for these tests.
|
|
||||||
maintainer = EmbeddingMaintainer.__new__(EmbeddingMaintainer)
|
|
||||||
maintainer.realtime_processors = []
|
|
||||||
maintainer.config = MagicMock()
|
|
||||||
maintainer.config.classification.custom = {}
|
|
||||||
maintainer.requestor = MagicMock()
|
|
||||||
maintainer.metrics = MagicMock()
|
|
||||||
maintainer.event_metadata_publisher = MagicMock()
|
|
||||||
return maintainer
|
|
||||||
|
|
||||||
def _make_model_config(self, name: str, enabled: bool) -> MagicMock:
|
|
||||||
model_config = MagicMock()
|
|
||||||
model_config.name = name
|
|
||||||
model_config.enabled = enabled
|
|
||||||
model_config.state_config = None
|
|
||||||
return model_config
|
|
||||||
|
|
||||||
def _make_processor(self, name: str) -> MagicMock:
|
|
||||||
processor = MagicMock(spec=CustomObjectClassificationProcessor)
|
|
||||||
processor.model_config = MagicMock()
|
|
||||||
processor.model_config.name = name
|
|
||||||
return processor
|
|
||||||
|
|
||||||
def test_disabled_update_tears_down_existing_processor(self):
|
|
||||||
"""Toggling a running model to disabled shuts down and drops its processor."""
|
|
||||||
maintainer = self._make_maintainer()
|
|
||||||
processor = self._make_processor("atli")
|
|
||||||
maintainer.realtime_processors = [processor]
|
|
||||||
|
|
||||||
maintainer._handle_custom_classification_update(
|
|
||||||
"config/classification/custom/atli",
|
|
||||||
self._make_model_config("atli", enabled=False),
|
|
||||||
)
|
|
||||||
|
|
||||||
processor.shutdown.assert_called_once()
|
|
||||||
self.assertEqual(maintainer.realtime_processors, [])
|
|
||||||
|
|
||||||
def test_disabled_update_does_not_register_processor(self):
|
|
||||||
"""A disabled model that has no processor is never registered."""
|
|
||||||
maintainer = self._make_maintainer()
|
|
||||||
|
|
||||||
maintainer._handle_custom_classification_update(
|
|
||||||
"config/classification/custom/atli",
|
|
||||||
self._make_model_config("atli", enabled=False),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(maintainer.realtime_processors, [])
|
|
||||||
|
|
||||||
def test_disabled_update_leaves_other_processors_untouched(self):
|
|
||||||
"""Disabling one model must not affect other running processors."""
|
|
||||||
maintainer = self._make_maintainer()
|
|
||||||
other = self._make_processor("simbi")
|
|
||||||
maintainer.realtime_processors = [other]
|
|
||||||
|
|
||||||
maintainer._handle_custom_classification_update(
|
|
||||||
"config/classification/custom/atli",
|
|
||||||
self._make_model_config("atli", enabled=False),
|
|
||||||
)
|
|
||||||
|
|
||||||
other.shutdown.assert_not_called()
|
|
||||||
self.assertEqual(maintainer.realtime_processors, [other])
|
|
||||||
|
|
||||||
def test_removed_model_tears_down_processor(self):
|
|
||||||
"""A None payload (model deleted) still shuts down its processor."""
|
|
||||||
maintainer = self._make_maintainer()
|
|
||||||
processor = self._make_processor("atli")
|
|
||||||
maintainer.realtime_processors = [processor]
|
|
||||||
|
|
||||||
maintainer._handle_custom_classification_update(
|
|
||||||
"config/classification/custom/atli", None
|
|
||||||
)
|
|
||||||
|
|
||||||
processor.shutdown.assert_called_once()
|
|
||||||
self.assertEqual(maintainer.realtime_processors, [])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
Reference in New Issue
Block a user