Avoid redundant numeric reads after consistent small-sign evidence

This commit is contained in:
firestar5683
2026-11-14 00:34:38 -06:00
parent d0e7b72633
commit bea8362cc4
3 changed files with 63 additions and 1 deletions
@@ -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
@@ -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()
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "091a924495f09501b675b8d2f35576b5db50375ac944138511506e17c4cf853b", "schema_version": 1}
{"protected_inventory_sha256": "5cc1b6cb4c15193b78e51dc0b0e20ec1a88c278b2dd4f43b44ad3e12af330c9d", "schema_version": 1}