From 37e2d3e296c776c830ab7c4b8fb0eef23bf37ec0 Mon Sep 17 00:00:00 2001 From: jetson Date: Thu, 15 Oct 2026 14:12:35 +0700 Subject: [PATCH] sync: mirror platform counting params (stabilizer hold, track_buffer, tracker iou) - stabilizer max_hold 10 -> 25 frames (~1s occlusion hold, platform parity) - cfg/tracker.yaml track_buffer 60 -> 90 (identical to platform now) - ByteTrackTracker gains iou=0.7 (passed to model.track, platform parity) - stabilizer/tracking modules now byte-identical to karung_counter_semarang - 177 tests pass --- cfg/tracker.yaml | 4 ++-- config.yaml | 2 +- src/config.py | 2 +- src/stabilizer.py | 4 ++-- src/tracking.py | 6 ++++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cfg/tracker.yaml b/cfg/tracker.yaml index 701328a..9748b2b 100644 --- a/cfg/tracker.yaml +++ b/cfg/tracker.yaml @@ -1,5 +1,5 @@ # Custom FastTrack config tuned for sack counting: -# - track_buffer=60: hold lost tracks for 60 frames (~2.4s at 25fps) +# - track_buffer=90: hold lost tracks for 90 frames (~3.6s at 25fps) # to survive worker occlusion # - new_track_thresh=0.3: harder to spawn duplicate IDs # - track_low_thresh=0.05: recover faint detections behind workers @@ -11,7 +11,7 @@ tracker_type: bytetrack track_high_thresh: 0.20 track_low_thresh: 0.05 new_track_thresh: 0.30 -track_buffer: 60 +track_buffer: 90 match_thresh: 0.85 fuse_score: true diff --git a/config.yaml b/config.yaml index 151e453..c41f20f 100644 --- a/config.yaml +++ b/config.yaml @@ -28,7 +28,7 @@ roi: stabilizer: ema_alpha: 0.35 - max_hold: 10 # frames to hold occluded tracks + max_hold: 25 # frames to hold occluded tracks (platform parity: 25 = ~1s @25fps) pipeline: detect_interval: 1 # detection+tracking every N frames (1 = every frame, most accurate) diff --git a/src/config.py b/src/config.py index 8114362..dfb0d62 100644 --- a/src/config.py +++ b/src/config.py @@ -38,7 +38,7 @@ DEFAULTS: dict = { }, "stabilizer": { "ema_alpha": 0.35, - "max_hold": 10, + "max_hold": 25, }, "pipeline": { "detect_interval": 1, diff --git a/src/stabilizer.py b/src/stabilizer.py index 3a33fdd..1a5a390 100644 --- a/src/stabilizer.py +++ b/src/stabilizer.py @@ -4,7 +4,7 @@ Addresses four occlusion/flickering problems: 1. Bbox jitter: raw detections jump 10-50px between frames. Fix: EMA (exponential moving average) on bbox coordinates. 2. Bbox loss at line: worker's head/body blocks sack for 5-10 frames. - Fix: hold last known smoothed bbox for `max_hold_frames` (10 frames). + Fix: hold last known smoothed bbox for `max_hold_frames` (25 frames). 3. Height expansion spike: worker body merges into sack bbox. Fix: clamp height expansion (`raw_h > smooth_h * max_h_ratio`). 4. Height shrinkage collapse: worker head/shoulder covers bottom of sack. @@ -24,7 +24,7 @@ class BboxStabilizer: def __init__( self, ema_alpha: float = 0.35, - max_hold_frames: int = 10, + max_hold_frames: int = 25, max_height_ratio: float = 1.5, min_height_ratio: float = 0.70, ) -> None: diff --git a/src/tracking.py b/src/tracking.py index c65cb3f..30ab8b5 100644 --- a/src/tracking.py +++ b/src/tracking.py @@ -6,7 +6,7 @@ Uses Ultralytics FastTrack which handles: - Re-identification of occluded tracks after reappearance Our custom cfg/tracker.yaml tunes: - - track_buffer=60 (hold lost tracks ~2.4s to survive worker occlusion) + - track_buffer=90 (hold lost tracks ~3.6s to survive worker occlusion) - new_track_thresh=0.3 (prevent duplicate IDs from spawning) - active_occ_to_lost_thresh=15 (tolerate 15 occluded frames) """ @@ -28,7 +28,7 @@ _TRACKER_CFG = os.path.join( class ByteTrackTracker: """Tracks sacks across frames using FastTrack (occlusion-aware).""" - def __init__(self, model_path: str | YOLO, conf: float = 0.35) -> None: + def __init__(self, model_path: str | YOLO, conf: float = 0.35, iou: float = 0.7) -> None: if isinstance(model_path, YOLO): self._model = model_path self._model_path = getattr(model_path, "ckpt_path", str(model_path)) @@ -36,6 +36,7 @@ class ByteTrackTracker: self._model = YOLO(model_path) self._model_path = model_path self._conf = conf + self._iou = iou self._tracker_cfg = _TRACKER_CFG if os.path.exists(_TRACKER_CFG) else "bytetrack.yaml" def update( @@ -45,6 +46,7 @@ class ByteTrackTracker: results = self._model.track( frame, conf=self._conf, + iou=self._iou, persist=True, tracker=self._tracker_cfg, verbose=False,