mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Sub label api score (#7113)
* Support setting sub label scores via API * Update docs * Update docs * Formatting * Throw error when score is outside expected bounds * Fix / cleanup
This commit is contained in:
parent
6d34f2229b
commit
6adc810145
@ -217,7 +217,8 @@ Sub labels must be 100 characters or shorter.
|
||||
|
||||
```json
|
||||
{
|
||||
"subLabel": "some_string"
|
||||
"subLabel": "some_string",
|
||||
"subLabelScore": 0.79,
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -74,7 +74,7 @@ Message published for each changed event. The first message is published when th
|
||||
"frame_time": 1607123962.082975,
|
||||
"snapshot_time": 1607123961.837752,
|
||||
"label": "person",
|
||||
"sub_label": null,
|
||||
"sub_label": ["John Smith", 0.79],
|
||||
"top_score": 0.958984375,
|
||||
"false_positive": false,
|
||||
"start_time": 1607123955.475377,
|
||||
|
@ -370,10 +370,9 @@ def set_sub_label(id):
|
||||
jsonify({"success": False, "message": "Event " + id + " not found"}), 404
|
||||
)
|
||||
|
||||
if request.json:
|
||||
new_sub_label = request.json.get("subLabel")
|
||||
else:
|
||||
new_sub_label = None
|
||||
json: dict[str, any] = request.get_json(silent=True) or {}
|
||||
new_sub_label = json.get("subLabel")
|
||||
new_score = json.get("subLabelScore")
|
||||
|
||||
if new_sub_label and len(new_sub_label) > 100:
|
||||
return make_response(
|
||||
@ -387,6 +386,18 @@ def set_sub_label(id):
|
||||
400,
|
||||
)
|
||||
|
||||
if new_score is not None and (new_score > 1.0 or new_score < 0):
|
||||
return make_response(
|
||||
jsonify(
|
||||
{
|
||||
"success": False,
|
||||
"message": new_score
|
||||
+ " does not fit within the expected bounds 0 <= score <= 1.0",
|
||||
}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
if not event.end_time:
|
||||
tracked_obj: TrackedObject = (
|
||||
current_app.detected_frames_processor.camera_states[
|
||||
@ -395,9 +406,15 @@ def set_sub_label(id):
|
||||
)
|
||||
|
||||
if tracked_obj:
|
||||
tracked_obj.obj_data["sub_label"] = new_sub_label
|
||||
tracked_obj.obj_data["sub_label"] = (new_sub_label, new_score)
|
||||
|
||||
event.sub_label = new_sub_label
|
||||
|
||||
if new_score:
|
||||
data = event.data
|
||||
data["sub_label_score"] = new_score
|
||||
event.data = data
|
||||
|
||||
event.save()
|
||||
return make_response(
|
||||
jsonify(
|
||||
|
Loading…
Reference in New Issue
Block a user