From ed572b7954eb84fc8363d53c713b6bd3bc5eeba1 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 5 Feb 2024 14:50:10 -0700 Subject: [PATCH] Use different nms values for different object types --- frigate/const.py | 4 ++++ frigate/util/object.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frigate/const.py b/frigate/const.py index ebb680333..dc666b9a9 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -26,6 +26,10 @@ LABEL_CONSOLIDATION_MAP = { "face": 0.5, } LABEL_CONSOLIDATION_DEFAULT = 0.9 +LABEL_NMS_MAP = { + "car": 0.7, +} +LABEL_NMS_DEFAULT = 0.4 # Audio Consts diff --git a/frigate/util/object.py b/frigate/util/object.py index 0bf7ea179..43ec017bb 100644 --- a/frigate/util/object.py +++ b/frigate/util/object.py @@ -10,7 +10,12 @@ import numpy as np from peewee import DoesNotExist from frigate.config import DetectConfig, ModelConfig -from frigate.const import LABEL_CONSOLIDATION_DEFAULT, LABEL_CONSOLIDATION_MAP +from frigate.const import ( + LABEL_CONSOLIDATION_DEFAULT, + LABEL_CONSOLIDATION_MAP, + LABEL_NMS_DEFAULT, + LABEL_NMS_MAP, +) from frigate.detectors.detector_config import PixelFormatEnum from frigate.models import Event, Regions, Timeline from frigate.util.image import ( @@ -466,6 +471,7 @@ def reduce_detections( selected_objects = [] for group in detected_object_groups.values(): + label = group[0][0] # o[2] is the box of the object: xmin, ymin, xmax, ymax # apply max/min to ensure values do not exceed the known frame size boxes = [ @@ -483,7 +489,9 @@ def reduce_detections( # due to min score requirement of NMSBoxes confidences = [0.6 if clipped(o, frame_shape) else o[1] for o in group] - idxs = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) + idxs = cv2.dnn.NMSBoxes( + boxes, confidences, 0.5, LABEL_NMS_MAP.get(label, LABEL_NMS_DEFAULT) + ) # add objects for index in idxs: