Skip to content

Commit

Permalink
Bug fixes (blakeblackshear#6332)
Browse files Browse the repository at this point in the history
* fix timeline delete

* fix labelmap in config response

* create cache dirs if needed
  • Loading branch information
blakeblackshear committed Apr 30, 2023
1 parent 9bf98f9 commit 1989031
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
6 changes: 3 additions & 3 deletions frigate/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,9 @@ def config():
config["plus"] = {"enabled": current_app.plus_api.is_active()}

for detector, detector_config in config["detectors"].items():
detector_config["model"]["labelmap"] = current_app.frigate_config.detectors[
detector
].model.merged_labelmap
detector_config["model"][
"labelmap"
] = current_app.frigate_config.model.merged_labelmap

return jsonify(config)

Expand Down
2 changes: 1 addition & 1 deletion frigate/record/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def expire_recordings(self) -> None:
deleted_recordings.add(recording.id)

# delete timeline entries relevant to this recording segment
Timeline.delete(
Timeline.delete().where(
Timeline.timestamp.between(
recording.start_time, recording.end_time
),
Expand Down
67 changes: 67 additions & 0 deletions frigate/test/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import os
import unittest
import numpy as np
from pydantic import ValidationError
Expand All @@ -6,7 +8,9 @@
BirdseyeModeEnum,
FrigateConfig,
)
from frigate.const import MODEL_CACHE_DIR
from frigate.detectors import DetectorTypeEnum
from frigate.plus import PlusApi
from frigate.util import deep_merge, load_config_with_no_duplicates


Expand All @@ -30,6 +34,35 @@ def setUp(self):
},
}

self.plus_model_info = {
"id": "e63b7345cc83a84ed79dedfc99c16616",
"name": "SSDLite Mobiledet",
"description": "Fine tuned model",
"trainDate": "2023-04-28T23:22:01.262Z",
"type": "ssd",
"supportedDetectors": ["edgetpu"],
"width": 320,
"height": 320,
"inputShape": "nhwc",
"pixelFormat": "rgb",
"labelMap": {
"0": "amazon",
"1": "car",
"2": "cat",
"3": "deer",
"4": "dog",
"5": "face",
"6": "fedex",
"7": "license_plate",
"8": "package",
"9": "person",
"10": "ups",
},
}

if not os.path.exists(MODEL_CACHE_DIR) and not os.path.islink(MODEL_CACHE_DIR):
os.makedirs(MODEL_CACHE_DIR)

def test_config_class(self):
frigate_config = FrigateConfig(**self.minimal)
assert self.minimal == frigate_config.dict(exclude_unset=True)
Expand Down Expand Up @@ -815,6 +848,40 @@ def test_default_labelmap(self):
runtime_config = frigate_config.runtime_config()
assert runtime_config.model.merged_labelmap[0] == "person"

def test_plus_labelmap(self):
with open("/config/model_cache/test", "w") as f:
json.dump(self.plus_model_info, f)
with open("/config/model_cache/test.json", "w") as f:
json.dump(self.plus_model_info, f)

config = {
"mqtt": {"host": "mqtt"},
"model": {"path": "plus:https://test"},
"cameras": {
"back": {
"ffmpeg": {
"inputs": [
{
"path": "rtsp:https://10.0.0.1:554/video",
"roles": ["detect"],
},
]
},
"detect": {
"height": 1080,
"width": 1920,
"fps": 5,
},
}
},
}

frigate_config = FrigateConfig(**config)
assert config == frigate_config.dict(exclude_unset=True)

runtime_config = frigate_config.runtime_config(PlusApi())
assert runtime_config.model.merged_labelmap[0] == "amazon"

def test_fails_on_invalid_role(self):
config = {
"mqtt": {"host": "mqtt"},
Expand Down

0 comments on commit 1989031

Please sign in to comment.