forked from andrew/feedmill-recounter
fix: scale min_bbox_area from platform 1280x720 reference to frame size
Platform force-resizes frames to 1280x720 before detection, so its 1500/5000 px2 thresholds are authored in that space. Applying them raw at native 1080p made recounter's effective bar 2.25x weaker — false divergence in double-check runs. _scaled_min_areas scales by frame area (1080p: 3375/11250, 720p: unchanged). Platform's get_min_valid_area perspective gate is dead code (zero call sites) — deliberately not ported, it would make recounter stricter than platform. 174 tests pass (+1).
This commit is contained in:
1 parent
92fd4cbb38
commit
c2d720e86c
3 files changed
+32
-3
No files matched your search
+2
-1
@@ -8,7 +8,8 @@ detection:
|
||||
box_conf: 0.35 # detector confidence for box
|
||||
truck_conf: 0.45 # truck detector confidence
|
||||
|
||||
# Per-class minimum bbox area (px^2) — drops tiny false positives.
|
||||
# Per-class minimum bbox area (px^2) — authored in platform's 1280x720
|
||||
# reference space; pipeline scales to actual frame size (physical parity).
|
||||
min_bbox_area:
|
||||
sack: 1500
|
||||
box: 1500
|
||||
|
||||
+14
-2
@@ -346,7 +346,7 @@ def run_pipeline(
|
||||
tracked_sacks, iou_threshold=cfg["iou"]["suppress_sack_box"]
|
||||
)
|
||||
tracked_sacks = _apply_class_confs(tracked_sacks, sack_conf, box_conf)
|
||||
tracked_sacks = _apply_min_area(tracked_sacks, cfg["min_bbox_area"])
|
||||
tracked_sacks = _apply_min_area(tracked_sacks, _scaled_min_areas(cfg, w, h))
|
||||
counter.update(countable_detections(tracked_sacks))
|
||||
|
||||
# Annotate frame
|
||||
@@ -509,6 +509,18 @@ def _apply_min_area(dets, areas):
|
||||
]
|
||||
|
||||
|
||||
# Platform (karung_counter_semarang) force-resizes frames to 1280x720 before
|
||||
# detection, so its min_bbox_area values are authored in that space. Scale by
|
||||
# frame area so the physical-size threshold matches on native 1080p input.
|
||||
PLATFORM_REF_AREA = 1280 * 720
|
||||
|
||||
|
||||
def _scaled_min_areas(cfg, frame_w: int, frame_h: int) -> dict:
|
||||
"""min_bbox_area scaled from platform's 1280x720 reference to frame size."""
|
||||
scale = (frame_w * frame_h) / PLATFORM_REF_AREA
|
||||
return {k: v * scale for k, v in cfg["min_bbox_area"].items()}
|
||||
|
||||
|
||||
def run_merged_pipeline(
|
||||
video_path: str,
|
||||
model_configs: list[ModelConfig],
|
||||
@@ -738,7 +750,7 @@ def run_merged_pipeline(
|
||||
tracked, iou_threshold=cfg["iou"]["suppress_sack_box"]
|
||||
)
|
||||
tracked = _apply_class_confs(tracked, sack_conf, box_conf)
|
||||
tracked = _apply_min_area(tracked, cfg["min_bbox_area"])
|
||||
tracked = _apply_min_area(tracked, _scaled_min_areas(cfg, w, h))
|
||||
|
||||
# Count using only detections with track_id (tracker results)
|
||||
counter.update(countable_detections([d for d in tracked if d.track_id is not None]))
|
||||
|
||||
@@ -371,6 +371,22 @@ def test_apply_min_area_per_class_thresholds():
|
||||
]
|
||||
|
||||
|
||||
def test_scaled_min_areas_platform_parity():
|
||||
"""1080p frames scale thresholds 2.25x; 720p stays at platform reference."""
|
||||
from src.pipeline import _scaled_min_areas
|
||||
|
||||
cfg = {"min_bbox_area": {"sack": 1500, "box": 1500, "truck": 5000}}
|
||||
|
||||
# Native 720p == platform's reference resolution → unchanged
|
||||
at_720p = _scaled_min_areas(cfg, 1280, 720)
|
||||
assert at_720p == {"sack": 1500, "box": 1500, "truck": 5000}
|
||||
|
||||
# 1080p: area ratio 2.25 → 1500 -> 3375, 5000 -> 11250
|
||||
at_1080p = _scaled_min_areas(cfg, 1920, 1080)
|
||||
assert at_1080p["sack"] == 3375
|
||||
assert at_1080p["truck"] == 11250
|
||||
|
||||
|
||||
# ── Perf/output tuning params (signature contracts) ────────────────────
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user