mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-22 05:23:01 +03:00
add default filters for labels tracked at runtime
Adding a tracked label through Debug Replay or a profile left it without an object filter, so the first detection raised a KeyError in the false positive check and killed detected_frames_processor, stopping detection on every camera. Runtime objects updates now create a default filter for each tracked label that lacks one, the same as startup.
This commit is contained in:
@@ -4,6 +4,7 @@ from unittest.mock import Mock, patch
|
|||||||
|
|
||||||
import frigate.genai
|
import frigate.genai
|
||||||
from frigate.config import GenAIProviderEnum
|
from frigate.config import GenAIProviderEnum
|
||||||
|
from frigate.config.config import RuntimeFilterConfig
|
||||||
from frigate.const import MODEL_CACHE_DIR, REDACTED_CREDENTIAL_SENTINEL
|
from frigate.const import MODEL_CACHE_DIR, REDACTED_CREDENTIAL_SENTINEL
|
||||||
from frigate.genai import GenAIClient
|
from frigate.genai import GenAIClient
|
||||||
from frigate.models import Event, Recordings, ReviewSegment
|
from frigate.models import Event, Recordings, ReviewSegment
|
||||||
@@ -98,6 +99,32 @@ class TestHttpApp(BaseTestHttp):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert app.frigate_config.cameras["front_door"].objects.track == ["person"]
|
assert app.frigate_config.cameras["front_door"].objects.track == ["person"]
|
||||||
|
|
||||||
|
def test_config_set_in_memory_adds_filters_for_new_tracked_labels(self):
|
||||||
|
self.minimal_config["cameras"]["front_door"]["objects"] = {
|
||||||
|
"track": ["person"],
|
||||||
|
}
|
||||||
|
app = super().create_app()
|
||||||
|
app.config_publisher = Mock()
|
||||||
|
|
||||||
|
with AuthTestClient(app) as client:
|
||||||
|
response = client.put(
|
||||||
|
"/config/set",
|
||||||
|
json={
|
||||||
|
"requires_restart": 0,
|
||||||
|
"skip_save": True,
|
||||||
|
"update_topic": "config/cameras/front_door/objects",
|
||||||
|
"config_data": {
|
||||||
|
"cameras": {
|
||||||
|
"front_door": {"objects": {"track": ["person", "cat"]}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
filters = app.frigate_config.cameras["front_door"].objects.filters
|
||||||
|
assert isinstance(filters["cat"], RuntimeFilterConfig)
|
||||||
|
|
||||||
@patch("frigate.detectors.detector_config.load_labels")
|
@patch("frigate.detectors.detector_config.load_labels")
|
||||||
def test_config_set_in_memory_rebinds_replay_model_on_scene_change(
|
def test_config_set_in_memory_rebinds_replay_model_on_scene_change(
|
||||||
self, mock_labels
|
self, mock_labels
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
from frigate.config import BirdseyeModeEnum, FrigateConfig
|
from frigate.config import BirdseyeModeEnum, FrigateConfig
|
||||||
from frigate.config.camera.profile import CameraProfileConfig
|
from frigate.config.camera.profile import CameraProfileConfig
|
||||||
|
from frigate.config.config import RuntimeFilterConfig
|
||||||
from frigate.config.profile import ProfileDefinitionConfig
|
from frigate.config.profile import ProfileDefinitionConfig
|
||||||
from frigate.config.profile_manager import PERSISTENCE_FILE, ProfileManager
|
from frigate.config.profile_manager import PERSISTENCE_FILE, ProfileManager
|
||||||
from frigate.const import MODEL_CACHE_DIR
|
from frigate.const import MODEL_CACHE_DIR
|
||||||
@@ -502,6 +503,16 @@ class TestProfileManager(unittest.TestCase):
|
|||||||
back = self.config.cameras["back"]
|
back = self.config.cameras["back"]
|
||||||
assert back.notifications.enabled is True
|
assert back.notifications.enabled is True
|
||||||
|
|
||||||
|
@patch.object(ProfileManager, "_persist_active_profile")
|
||||||
|
def test_activate_profile_adds_filters_for_new_tracked_labels(self, mock_persist):
|
||||||
|
"""Labels a profile adds to objects.track get default filters."""
|
||||||
|
err = self.manager.activate_profile("armed")
|
||||||
|
assert err is None
|
||||||
|
|
||||||
|
filters = self.config.cameras["front"].objects.filters
|
||||||
|
for label in ["person", "car", "package"]:
|
||||||
|
assert isinstance(filters[label], RuntimeFilterConfig)
|
||||||
|
|
||||||
@patch.object(ProfileManager, "_persist_active_profile")
|
@patch.object(ProfileManager, "_persist_active_profile")
|
||||||
def test_deactivate_profile(self, mock_persist):
|
def test_deactivate_profile(self, mock_persist):
|
||||||
"""Deactivating a profile restores base config."""
|
"""Deactivating a profile restores base config."""
|
||||||
|
|||||||
@@ -1191,7 +1191,11 @@ def apply_section_update(camera_config, section: str, update: dict) -> str | Non
|
|||||||
Returns:
|
Returns:
|
||||||
None on success, or an error message string on failure.
|
None on success, or an error message string on failure.
|
||||||
"""
|
"""
|
||||||
from frigate.config.config import RuntimeFilterConfig, RuntimeMotionConfig
|
from frigate.config.config import (
|
||||||
|
FilterConfig,
|
||||||
|
RuntimeFilterConfig,
|
||||||
|
RuntimeMotionConfig,
|
||||||
|
)
|
||||||
|
|
||||||
current = getattr(camera_config, section, None)
|
current = getattr(camera_config, section, None)
|
||||||
if current is None:
|
if current is None:
|
||||||
@@ -1224,6 +1228,9 @@ def apply_section_update(camera_config, section: str, update: dict) -> str | Non
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
for label in new_objects.track:
|
||||||
|
new_objects.filters.setdefault(label, FilterConfig())
|
||||||
|
|
||||||
# Rebuild RuntimeFilterConfig with merged global + per-object masks
|
# Rebuild RuntimeFilterConfig with merged global + per-object masks
|
||||||
for obj_name, filt in new_objects.filters.items():
|
for obj_name, filt in new_objects.filters.items():
|
||||||
merged_mask = dict(filt.mask)
|
merged_mask = dict(filt.mask)
|
||||||
|
|||||||
Reference in New Issue
Block a user