From bea8362cc4c3f45ba6d6549cdcc823cd47a4c655 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:34:38 -0600 Subject: [PATCH] Avoid redundant numeric reads after consistent small-sign evidence --- .../starpilot/speed_limits/vision/model.py | 11 ++++ .../vision/tests/test_small_object_repeat.py | 51 +++++++++++++++++++ prebuilt.json | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 openpilot/starpilot/speed_limits/vision/tests/test_small_object_repeat.py diff --git a/openpilot/starpilot/speed_limits/vision/model.py b/openpilot/starpilot/speed_limits/vision/model.py index c1d7f107db..830d54431c 100644 --- a/openpilot/starpilot/speed_limits/vision/model.py +++ b/openpilot/starpilot/speed_limits/vision/model.py @@ -1270,6 +1270,17 @@ class VisionModelCore: self._remember_detector_proposal( proposal_confidence, class_id, (x1, y1, x2, y2), speed_limit_mph, preferred=True, ) + if (type(proposals) is list and class_id == 0 and is_small_box and + published_score == DETECTOR_CLASSIFIER_RESCUE_MAX_SCORE and + expansions is DETECTOR_CLASSIFIER_EXPANSIONS and support_count == 3 and len(speed_scores) == 1): + for _, future_class, (a, b, c, d) in proposals[proposal_index + 1:]: + overlap = max(0, min(x2, c) - max(x1, a)) * max(0, min(y2, d) - max(y1, b)) + union = box_width * box_height + (c - a) * (d - b) - overlap + if future_class != 0 or overlap <= .8 * union: + break + else: + # Keep the existing weak result after three agreeing crops of one object. + return None if best_retry_conflict else best_detection if best_detection is not None and best_detection.confidence >= MODEL_DETECTION_SHORT_CIRCUIT_CONFIDENCE: return None if best_retry_conflict else best_detection diff --git a/openpilot/starpilot/speed_limits/vision/tests/test_small_object_repeat.py b/openpilot/starpilot/speed_limits/vision/tests/test_small_object_repeat.py new file mode 100644 index 0000000000..b6f2ad927c --- /dev/null +++ b/openpilot/starpilot/speed_limits/vision/tests/test_small_object_repeat.py @@ -0,0 +1,51 @@ +import unittest + +import numpy as np + +from openpilot.starpilot.speed_limits.vision.tests.test_retry_consistency import core_fixture, probabilities + + +class TestSmallObjectRepeat(unittest.TestCase): + def setUp(self): + self.frame = np.random.default_rng(21).integers(0, 256, (760, 1344, 3), dtype=np.uint8) + self.proposals = [(.8, 0, (800, 300, 825, 331)), (.7, 0, (799, 300, 826, 332)), + (.6, 0, (800, 301, 826, 331))] + + def core(self, proposals=None, values=None): + values = values or [50] * 9 + reads = [(probabilities(value, .94), probabilities(value, .94)) for value in values] + return core_fixture(reads, [True] * 20, proposals or self.proposals) + + def test_three_agreeing_crops_keep_the_weak_result_without_duplicate_reads(self): + core = self.core() + detection = core.infer(self.frame) + self.assertEqual(detection.speed_limit_mph, 50) + self.assertEqual(detection.confidence, .64) + self.assertFalse(detection.strong_consensus) + self.assertEqual(core.classifier_net.calls, 3) + + def test_distinct_objects_still_receive_their_numeric_reads(self): + core = self.core([*self.proposals, (.5, 0, (900, 300, 925, 331))], [50] * 12) + self.assertIsNotNone(core.infer(self.frame)) + self.assertGreater(core.classifier_net.calls, 3) + + def test_conflicting_crops_do_not_suppress_later_proposals(self): + core = self.core(values=[50, 40, 50, 50, 50, 50, 50, 50, 50]) + self.assertIsNotNone(core.infer(self.frame)) + self.assertGreater(core.classifier_net.calls, 3) + + def test_weak_read_does_not_replace_a_confirmed_limit(self): + core = self.core() + core.published_speed_limit_mph = 60 + core.published_confidence = .95 + core.published_support_count = 1 + core.previous_published_speed_limit_mph = 0 + core.last_publish_change_at = 1. + core.episode = 1 + result = core.observe(self.frame, now=100.) + self.assertEqual(result, (60, .95, 1, 1)) + self.assertEqual(core.classifier_net.calls, 3) + + +if __name__ == '__main__': + unittest.main() diff --git a/prebuilt.json b/prebuilt.json index 856fe1b519..d1f393fab7 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "091a924495f09501b675b8d2f35576b5db50375ac944138511506e17c4cf853b", "schema_version": 1} +{"protected_inventory_sha256": "5cc1b6cb4c15193b78e51dc0b0e20ec1a88c278b2dd4f43b44ad3e12af330c9d", "schema_version": 1}