refactor: keep tag state in streamed track only
This commit is contained in:
parent
e9279c58b3
commit
19af7ce545
2 changed files with 1 additions and 65 deletions
|
|
@ -191,10 +191,6 @@ class LiveSession:
|
||||||
self._shift_map = None
|
self._shift_map = None
|
||||||
self._compliance_tracker = None
|
self._compliance_tracker = None
|
||||||
self._last_compliance: Dict[str, Any] = {"violations": 0, "by_rule": {}, "rows": []}
|
self._last_compliance: Dict[str, Any] = {"violations": 0, "by_rule": {}, "rows": []}
|
||||||
# Settled tag + reconciliation from the last result, keyed by track.
|
|
||||||
# Inspect copies these; it does not re-run OCR.
|
|
||||||
self._settled_tags: Dict[int, Dict[str, Any]] = {}
|
|
||||||
self._settled_tag_seq = 0
|
|
||||||
self._label_memory: "collections.deque[Dict[str, Any]]" = collections.deque(
|
self._label_memory: "collections.deque[Dict[str, Any]]" = collections.deque(
|
||||||
maxlen=LABEL_MEMORY_MAX
|
maxlen=LABEL_MEMORY_MAX
|
||||||
)
|
)
|
||||||
|
|
@ -297,8 +293,6 @@ class LiveSession:
|
||||||
self._latest_frame_id = None
|
self._latest_frame_id = None
|
||||||
self._frame_origin = [0.0, 0.0]
|
self._frame_origin = [0.0, 0.0]
|
||||||
self._shift_map = None
|
self._shift_map = None
|
||||||
self._settled_tags = {}
|
|
||||||
self._settled_tag_seq = 0
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------ frame path
|
# ------------------------------------------------------------------ frame path
|
||||||
def process_frame(self, frame_id: int, payload: bytes) -> Dict[str, Any]:
|
def process_frame(self, frame_id: int, payload: bytes) -> Dict[str, Any]:
|
||||||
|
|
@ -445,17 +439,6 @@ class LiveSession:
|
||||||
if tag_summary is not None:
|
if tag_summary is not None:
|
||||||
summary["price_tags"] = tag_summary["tags"]
|
summary["price_tags"] = tag_summary["tags"]
|
||||||
summary["compliance"] = tag_summary["compliance"]
|
summary["compliance"] = tag_summary["compliance"]
|
||||||
settled: Dict[int, Dict[str, Any]] = {}
|
|
||||||
for payload in track_payload:
|
|
||||||
snapshot: Dict[str, Any] = {}
|
|
||||||
if "price_tag" in payload:
|
|
||||||
snapshot["price_tag"] = payload["price_tag"]
|
|
||||||
if "reconciliation" in payload:
|
|
||||||
snapshot["reconciliation"] = payload["reconciliation"]
|
|
||||||
if snapshot:
|
|
||||||
settled[int(payload["track_id"])] = snapshot
|
|
||||||
self._settled_tags = settled
|
|
||||||
self._settled_tag_seq = seq
|
|
||||||
|
|
||||||
self._submit_classification(submissions, method, generation)
|
self._submit_classification(submissions, method, generation)
|
||||||
self._run_tag_passes(image, tag_bands)
|
self._run_tag_passes(image, tag_bands)
|
||||||
|
|
@ -929,16 +912,7 @@ class LiveSession:
|
||||||
if track is None or image is None:
|
if track is None or image is None:
|
||||||
raise KeyError("TRACK_NOT_IN_VIEW")
|
raise KeyError("TRACK_NOT_IN_VIEW")
|
||||||
box = list(track.raw_box)
|
box = list(track.raw_box)
|
||||||
# Snapshot is the frame current at tap time. engine.inspect runs
|
return self.engine.inspect(image, box, method=chosen_method)
|
||||||
# outside the lock, so a newer frame may land first; the reply still
|
|
||||||
# carries the tag from the frame the tap matched, not that later one.
|
|
||||||
settled = None
|
|
||||||
if self._settled_tag_seq == self._latest_seq:
|
|
||||||
settled = self._settled_tags.get(track_id)
|
|
||||||
result = self.engine.inspect(image, box, method=chosen_method)
|
|
||||||
if settled:
|
|
||||||
result.update(settled)
|
|
||||||
return result
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------ catalog cache
|
# ------------------------------------------------------------------ catalog cache
|
||||||
def refresh_catalog(self) -> None:
|
def refresh_catalog(self) -> None:
|
||||||
|
|
|
||||||
|
|
@ -385,44 +385,6 @@ class ClassificationBudgetTests(unittest.TestCase):
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
session.inspect(999)
|
session.inspect(999)
|
||||||
|
|
||||||
def test_inspect_includes_settled_tag_from_the_latest_frame(self):
|
|
||||||
session, engine, _, _ = make_session()
|
|
||||||
tag = {"state": "readable", "price": 150, "box": [100, 270, 200, 320]}
|
|
||||||
|
|
||||||
class Tagged:
|
|
||||||
def plan(self, boxes, image_shape, shelf_offset=None):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def attach(self, tracks):
|
|
||||||
by_track = {int(track["track_id"]): dict(tag) for track in tracks}
|
|
||||||
return by_track, list(by_track.values()), {"readable": len(by_track)}
|
|
||||||
|
|
||||||
def stats(self):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
session._tags = Tagged()
|
|
||||||
result = process(session, 1)
|
|
||||||
track = result["tracks"][0]
|
|
||||||
track_id = track["track_id"]
|
|
||||||
self.assertEqual(track["price_tag"]["price"], 150)
|
|
||||||
self.assertIn("reconciliation", track)
|
|
||||||
|
|
||||||
inspected = session.inspect(track_id)
|
|
||||||
self.assertEqual(inspected["price_tag"], track["price_tag"])
|
|
||||||
self.assertEqual(inspected["reconciliation"], track["reconciliation"])
|
|
||||||
self.assertIn("identity", inspected)
|
|
||||||
|
|
||||||
session._tags = None
|
|
||||||
bare = process(session, 2)
|
|
||||||
self.assertNotIn("price_tag", bare["tracks"][0])
|
|
||||||
inspected_bare = session.inspect(track_id)
|
|
||||||
self.assertNotIn("price_tag", inspected_bare)
|
|
||||||
self.assertNotIn("reconciliation", inspected_bare)
|
|
||||||
|
|
||||||
session.reset()
|
|
||||||
with self.assertRaises(KeyError):
|
|
||||||
session.inspect(track_id)
|
|
||||||
engine.shutdown()
|
|
||||||
|
|
||||||
def test_close_stops_the_loop(self):
|
def test_close_stops_the_loop(self):
|
||||||
session, engine, _, _ = make_session()
|
session, engine, _, _ = make_session()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue