From e12b2dc68c2316f09280ef82ce9779fc9a82af00 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Sat, 26 Oct 2024 17:27:02 -0500 Subject: [PATCH] Prevent division by zero in lpr confidence checks (#14615) --- frigate/embeddings/maintainer.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index 00804c63f..2084e6b7a 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -599,14 +599,20 @@ class EmbeddingMaintainer(threading.Thread): return top_plate, top_char_confidences = license_plates[0], confidences[0] - avg_confidence = sum(top_char_confidences) / len(top_char_confidences) + avg_confidence = ( + (sum(top_char_confidences) / len(top_char_confidences)) + if top_char_confidences + else 0 + ) # Check if we have a previously detected plate for this ID if id in self.detected_license_plates: prev_plate = self.detected_license_plates[id]["plate"] prev_char_confidences = self.detected_license_plates[id]["char_confidences"] - prev_avg_confidence = sum(prev_char_confidences) / len( - prev_char_confidences + prev_avg_confidence = ( + (sum(prev_char_confidences) / len(prev_char_confidences)) + if prev_char_confidences + else 0 ) # Define conditions for keeping the previous plate