mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-02-14 00:17:05 +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
|
```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,
|
"frame_time": 1607123962.082975,
|
||||||
"snapshot_time": 1607123961.837752,
|
"snapshot_time": 1607123961.837752,
|
||||||
"label": "person",
|
"label": "person",
|
||||||
"sub_label": null,
|
"sub_label": ["John Smith", 0.79],
|
||||||
"top_score": 0.958984375,
|
"top_score": 0.958984375,
|
||||||
"false_positive": false,
|
"false_positive": false,
|
||||||
"start_time": 1607123955.475377,
|
"start_time": 1607123955.475377,
|
||||||
|
@ -370,10 +370,9 @@ def set_sub_label(id):
|
|||||||
jsonify({"success": False, "message": "Event " + id + " not found"}), 404
|
jsonify({"success": False, "message": "Event " + id + " not found"}), 404
|
||||||
)
|
)
|
||||||
|
|
||||||
if request.json:
|
json: dict[str, any] = request.get_json(silent=True) or {}
|
||||||
new_sub_label = request.json.get("subLabel")
|
new_sub_label = json.get("subLabel")
|
||||||
else:
|
new_score = json.get("subLabelScore")
|
||||||
new_sub_label = None
|
|
||||||
|
|
||||||
if new_sub_label and len(new_sub_label) > 100:
|
if new_sub_label and len(new_sub_label) > 100:
|
||||||
return make_response(
|
return make_response(
|
||||||
@ -387,6 +386,18 @@ def set_sub_label(id):
|
|||||||
400,
|
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:
|
if not event.end_time:
|
||||||
tracked_obj: TrackedObject = (
|
tracked_obj: TrackedObject = (
|
||||||
current_app.detected_frames_processor.camera_states[
|
current_app.detected_frames_processor.camera_states[
|
||||||
@ -395,9 +406,15 @@ def set_sub_label(id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if tracked_obj:
|
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
|
event.sub_label = new_sub_label
|
||||||
|
|
||||||
|
if new_score:
|
||||||
|
data = event.data
|
||||||
|
data["sub_label_score"] = new_score
|
||||||
|
event.data = data
|
||||||
|
|
||||||
event.save()
|
event.save()
|
||||||
return make_response(
|
return make_response(
|
||||||
jsonify(
|
jsonify(
|
||||||
|
Loading…
Reference in New Issue
Block a user