Refactor attribute saving (#14090)

* Refactor attribute saving

* Ensure sub label is not overwritten

* Formatting

* Fix unused
This commit is contained in:
Nicolas Mowen
2024-10-01 07:31:03 -06:00
committed by GitHub
parent 594ca3a04b
commit 15fa55c223
4 changed files with 130 additions and 22 deletions

View File

@@ -108,7 +108,12 @@ def is_better_thumbnail(label, current_thumb, new_obj, frame_shape) -> bool:
class TrackedObject:
def __init__(
self, camera, colormap, camera_config: CameraConfig, frame_cache, obj_data
self,
camera,
colormap,
camera_config: CameraConfig,
frame_cache,
obj_data: dict[str, any],
):
# set the score history then remove as it is not part of object state
self.score_history = obj_data["score_history"]
@@ -227,8 +232,8 @@ class TrackedObject:
if self.attributes[attr["label"]] < attr["score"]:
self.attributes[attr["label"]] = attr["score"]
# populate the sub_label for car with highest scoring logo
if self.obj_data["label"] == "car":
# populate the sub_label for object with highest scoring logo
if self.obj_data["label"] in ["car", "package", "person"]:
recognized_logos = {
k: self.attributes[k]
for k in ["ups", "fedex", "amazon"]
@@ -236,7 +241,13 @@ class TrackedObject:
}
if len(recognized_logos) > 0:
max_logo = max(recognized_logos, key=recognized_logos.get)
self.obj_data["sub_label"] = (max_logo, recognized_logos[max_logo])
# don't overwrite sub label if it is already set
if (
self.obj_data.get("sub_label") is None
or self.obj_data["sub_label"][0] == max_logo
):
self.obj_data["sub_label"] = (max_logo, recognized_logos[max_logo])
# check for significant change
if not self.false_positive: