forked from Github/frigate
Attribute scores (#7100)
* rework attributes to get scores * show sublabel score * formatting
This commit is contained in:
@@ -199,7 +199,8 @@ class EventProcessor(threading.Thread):
|
||||
|
||||
# only overwrite the sub_label in the database if it's set
|
||||
if event_data.get("sub_label") is not None:
|
||||
event[Event.sub_label] = event_data["sub_label"]
|
||||
event[Event.sub_label] = event_data["sub_label"][0]
|
||||
event[Event.data]["sub_label_score"] = event_data["sub_label"][1]
|
||||
|
||||
(
|
||||
Event.insert(event)
|
||||
|
||||
@@ -38,7 +38,9 @@ class Event(Model): # type: ignore[misc]
|
||||
IntegerField()
|
||||
) # TODO remove when columns can be dropped without rebuilding table
|
||||
retain_indefinitely = BooleanField(default=False)
|
||||
ratio = FloatField(default=1.0)
|
||||
ratio = FloatField(
|
||||
default=1.0
|
||||
) # TODO remove when columns can be dropped without rebuilding table
|
||||
plus_id = CharField(max_length=30)
|
||||
model_hash = CharField(max_length=32)
|
||||
detector_type = CharField(max_length=32)
|
||||
|
||||
@@ -112,7 +112,7 @@ class TrackedObject:
|
||||
self.zone_presence = {}
|
||||
self.current_zones = []
|
||||
self.entered_zones = []
|
||||
self.attributes = set()
|
||||
self.attributes = defaultdict(float)
|
||||
self.false_positive = True
|
||||
self.has_clip = False
|
||||
self.has_snapshot = False
|
||||
@@ -207,15 +207,19 @@ class TrackedObject:
|
||||
|
||||
# maintain attributes
|
||||
for attr in obj_data["attributes"]:
|
||||
self.attributes.add(attr["label"])
|
||||
if self.attributes[attr["label"]] < attr["score"]:
|
||||
self.attributes[attr["label"]] = attr["score"]
|
||||
|
||||
# populate the sub_label for car with first logo if it exists
|
||||
if self.obj_data["label"] == "car" and "sub_label" not in self.obj_data:
|
||||
recognized_logos = self.attributes.intersection(
|
||||
set(["ups", "fedex", "amazon"])
|
||||
)
|
||||
# populate the sub_label for car with highest scoring logo
|
||||
if self.obj_data["label"] == "car":
|
||||
recognized_logos = {
|
||||
k: self.attributes[k]
|
||||
for k in ["ups", "fedex", "amazon"]
|
||||
if k in self.attributes
|
||||
}
|
||||
if len(recognized_logos) > 0:
|
||||
self.obj_data["sub_label"] = recognized_logos.pop()
|
||||
max_logo = max(recognized_logos, key=recognized_logos.get)
|
||||
self.obj_data["sub_label"] = (max_logo, recognized_logos[max_logo])
|
||||
|
||||
# check for significant change
|
||||
if not self.false_positive:
|
||||
@@ -274,7 +278,7 @@ class TrackedObject:
|
||||
"entered_zones": self.entered_zones.copy(),
|
||||
"has_clip": self.has_clip,
|
||||
"has_snapshot": self.has_snapshot,
|
||||
"attributes": list(self.attributes),
|
||||
"attributes": self.attributes,
|
||||
"current_attributes": self.obj_data["attributes"],
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user