docs: changelog for the FCP counting-parity branch and plan corrections
CHANGELOG: the thresholds, cadence, count-line window, batch lifecycle, fail-fast config and truncation-flag changes, with their consequences for the published counts. The Task 0 entry now says the annotated output is 1280x720 (an explicit output_height below 720 still downscales it). Plan: add the Task 11 section (FCP's calibrated count-line x-window), correct the Task 1 and Task 7 FCP citations, and refresh the file structure and the verification snippet.
This commit is contained in:
1 parent
76b902d318
commit
23ede68f28
2 files changed
+111
-11
No files matched your search
+42
-2
@@ -40,6 +40,45 @@ version tags are cut in this repo — `main` is the release line).
|
||||
filename fallback for legacy callers).
|
||||
|
||||
### Changed
|
||||
- **FCP detection thresholds and cadence** (`3c354c6`, `70acfbb`, `acc74dc`):
|
||||
`detection.sack_conf` 0.40 → **0.30**, `min_bbox_area.box` 1500 → **1000**
|
||||
(FCP `config.yaml:83-93`), `stabilizer.max_hold` 25 → **10**
|
||||
(FCP `predict.py:668`), `pipeline.truck_det_interval` 15 → **5**
|
||||
(FCP `predict.py:882`). The truck ROI now refreshes 3× faster, so a batch
|
||||
opens and closes sooner.
|
||||
**Consequence: published counts can change for every clip** — the sac
|
||||
confidence gate is looser, the box area threshold is lower, and the
|
||||
occlusion hold is shorter (a sack hidden for more than 10 frames can be
|
||||
lost).
|
||||
- **Counting happens inside FCP's calibrated count-line x-window** (`8a82b8b`):
|
||||
the counter now uses the calibrated `count_line` x-range from `zones.json`
|
||||
(`384...934` in the 1280x720 analysis frame, FCP `predict.py:701-703`)
|
||||
instead of the truck-ROI bounds (`400...936`). The ROI x-filter
|
||||
(`400...936`, FCP `predict.py:541-548`) still applies, so the effective
|
||||
window is `400...934` on both sides.
|
||||
**Consequence: in fixed-zone mode a crossing whose bbox centre falls in
|
||||
`(934, 936]` no longer counts.**
|
||||
- **Batch lifecycle driven by real crossings** (`fc94189`): the batch FSM now
|
||||
receives the real crossing events and the real sack-in-truck-area count
|
||||
(FCP `predict.py:1064-1085`) instead of a hardcoded "no crossing" flag, so
|
||||
the idle timeout and the per-batch counts follow the sacks.
|
||||
Per-track counting state is cleared at every batch start while the clip
|
||||
totals are kept (`5e4add2`) — FCP clears its counter after finalising a
|
||||
batch row (`predict.py:1139-1150`); the recounter clears at batch start
|
||||
because it reports one cumulative count per clip.
|
||||
**Consequence: the per-batch counts in the job result can change.**
|
||||
- **Invalid configuration now fails fast** (`fcafc98`): a broken `config.yaml`
|
||||
raises instead of silently falling back to the built-in defaults (a missing
|
||||
file still falls back). Detection confidences must be in `(0, 1]`, IoU
|
||||
thresholds in `(0, 1]`, minimum bbox areas `>= 0`; the offending key and
|
||||
value are named in the error. A job whose config is broken fails with that
|
||||
message instead of counting with the wrong thresholds.
|
||||
- **Truncated clips are flagged** (`3d9cce2`): a clip whose decoded frame
|
||||
count is more than 2 % below the container's frame count is reported as
|
||||
`truncated: true` (with `frames_expected`) in the job result and in
|
||||
`GET /api/jobs` / `GET /api/jobs/<id>`. The counts are still reported —
|
||||
they cover the frames that were decoded. A cancelled job also reports
|
||||
`truncated: true` (the decoder stopped early).
|
||||
- **Counts limited to the calibrated counting polygon** (`d74ca41`): a
|
||||
detection is counted only when its bbox centre lies inside the calibrated
|
||||
`counting_area` (FCP's `detection_polygon` filter, `predict.py:939-942`).
|
||||
@@ -61,8 +100,9 @@ version tags are cut in this repo — `main` is the release line).
|
||||
- **Analysis frame pinned to 1280x720, model input pinned to 640x640**
|
||||
(`fcdfed1`): every decoded frame is resized to 1280x720 before detection
|
||||
(FCP `predict.py:826`) and both models run with an explicit `imgsz=640`
|
||||
(FCP `predict.py:467`). The annotated output is written at exactly
|
||||
1280x720. The static zone ROI is built in the 1280x720 frame
|
||||
(FCP `predict.py:467`). The annotated output is written at 1280x720
|
||||
(an explicit `output_height` below 720 still downscales it). The static
|
||||
zone ROI is built in the 1280x720 frame
|
||||
(`build_static_roi(zone, *ANALYSIS_SIZE)`), so the count line (`y=220`) and
|
||||
the ROI x-window (`400...936`) match FCP's for every clip. Consequence:
|
||||
clips whose native resolution is not 1280x720 now publish FCP's geometry;
|
||||
|
||||
@@ -65,11 +65,12 @@ Six failure modes a reasonable person would expect to be handled, each pinned to
|
||||
|
||||
**Modify**
|
||||
- `src/counting.py` — `_loaded_tracks` gate (Task 1), `reset_state()` (Task 7).
|
||||
- `src/zone_config.py` — expose counting-area + truck-area polygons (Task 3, 6).
|
||||
- `src/pipeline.py` — fixed 1280×720 analysis frame (Task 0), polygon filter (Task 3), real batch events (Task 6), batch-start reset hook (Task 7), truncation flag (Task 10).
|
||||
- `src/zone_config.py` — expose counting-area + truck-area polygons (Task 3, 6), carry the calibrated count-line x-window (Task 11).
|
||||
- `src/pipeline.py` — fixed 1280×720 analysis frame (Task 0), polygon filter (Task 3), real batch events (Task 6), batch-start reset hook (Task 7), truncation flag (Task 10), count-line x-window (Task 11).
|
||||
- `src/batch.py` — none required; `update_sacks()` already accepts real events (`src/batch.py:199`).
|
||||
- `src/config.py` — fail-fast load + validation call (Task 9).
|
||||
- `src/job.py` — `JobResult.truncated` / `frames_expected` (Task 10).
|
||||
- `src/truck_roi.py` — optional `line_x_start` / `line_x_end` on `TruckROI` (Task 11).
|
||||
- `config.yaml` — parity values (Tasks 4, 5, 8).
|
||||
- `src/tracking.py` — explicit `imgsz=640` (Task 0).
|
||||
- `src/detection.py` — explicit `imgsz=640` (Task 0).
|
||||
@@ -255,7 +256,7 @@ git commit -m "feat: analyse and write at 1280x720 with a pinned 640x640 model i
|
||||
- Consumes: existing `LineCrossCounter(line_y, line_x_start, line_x_end, margin=20, dedup_radius=30.0)`, `.loading_count`, `.unloading_count`, `.update(detections) -> list[dict]`, `.reset()`.
|
||||
- Produces: `LineCrossCounter._loaded_tracks: set[int]`.
|
||||
|
||||
FCP reference: `src/counting.py:168` (`and tid in self._loaded_tracks`), `:196` (`self._loaded_tracks.add(tid)`), `:235` (cleared in `reset()`), `:68` (declaration).
|
||||
FCP reference: `src/counting.py:171` (`and tid in self._loaded_tracks`), `:199` (`self._loaded_tracks.add(tid)`), `:241` (cleared in `reset()`), `:70` (declaration).
|
||||
|
||||
- [ ] **Step 1: Write the failing tests** — create `tests/test_counting.py`:
|
||||
|
||||
@@ -294,7 +295,7 @@ def test_loading_then_unloading_counts_both():
|
||||
|
||||
|
||||
def test_reset_clears_loaded_tracks():
|
||||
"""reset() clears the loaded-track registry (FCP src/counting.py:235)."""
|
||||
"""reset() clears the loaded-track registry (FCP src/counting.py:241)."""
|
||||
c = LineCrossCounter(line_y=100, line_x_start=0, line_x_end=1000)
|
||||
c.update([_det(1, 10)])
|
||||
c.update([_det(1, 200)])
|
||||
@@ -702,9 +703,9 @@ git commit -m "fix: drive batch FSM with real crossing events (FCP predict.py:10
|
||||
- Test: `tests/test_counting.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `LineCrossCounter.reset_state() -> None` — clears `_state`, `_has_been_above`, `_has_been_below`, `_counted`, `_loaded_tracks` but **keeps** `loading_count` / `unloading_count` totals.
|
||||
- Produces: `LineCrossCounter.reset_state() -> None` — clears `_state`, `_has_been_above`, `_has_been_below`, `_counted`, `_entry_points`, `_dedup_circles`, `_loaded_tracks` but **keeps** `loading_count` / `unloading_count` totals. `MultiClassLineCounter.reset_state()` delegates to both sub-counters.
|
||||
|
||||
FCP reference: `predict.py:1020-1032` and `:1148-1150` call `counter.reset()`, `stabilizer.reset()`, `box_stabilizer.reset()` when a batch starts.
|
||||
FCP reference (corrected while implementing — the original citation was wrong): FCP calls `counter.reset()`, `stabilizer.reset()`, `box_stabilizer.reset()` **after** it finalises a batch row (`predict.py:1139-1150`) and on manual mode switches (`predict.py:1020-1032`) — never at an automatic batch start. The recounter clears at batch start instead, because it keeps the clip-level totals; same per-batch isolation, different timing.
|
||||
|
||||
**Why not a plain `reset()`:** the recounter reports ONE cumulative count per clip/job. FCP writes one DB row per batch, so resetting its totals is harmless there; here it would drop the earlier truck sessions' counts. `reset_state()` gives the per-batch isolation FCP wants while keeping the clip-level total. Mark the ceiling with a `ponytail:` comment naming the upgrade path (per-batch result rows).
|
||||
|
||||
@@ -922,6 +923,65 @@ git commit -m "feat: flag truncated clips in the job result"
|
||||
|
||||
---
|
||||
|
||||
### Task 11: Carry FCP's calibrated count-line x-window into the counter
|
||||
|
||||
> Added while implementing (the task list missed a real counting-parity gap). Every other
|
||||
> value in this plan is pinned to an FCP `file:line`; so is this one.
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/truck_roi.py` (`TruckROI` gains optional `line_x_start` / `line_x_end`)
|
||||
- Modify: `src/zone_config.py` (`build_static_roi` populates them)
|
||||
- Modify: `src/pipeline.py` (both runners drive the counter from them)
|
||||
- Test: `tests/test_zone_config.py`, `tests/test_pipeline.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `TruckROI.line_x_start: int | None = None`, `TruckROI.line_x_end: int | None = None`.
|
||||
- `build_static_roi(zone, video_w, video_h)` sets them from the zone's `count_line` (scaled exactly like `line_y` already is) — `None` when the zone has no `count_line`.
|
||||
- Both runners: `counter.line_x_start` / `counter.line_x_end` come from the ROI's count-line window when it has one, else they keep the current fallback (`roi.x1` / `roi.x2` — the auto-detected truck-ROI bounds).
|
||||
|
||||
FCP reference: `predict.py:701-703` — `static_line_x_start = int(577 * scale_x)`, `static_line_x_end = int(1401 * scale_x)`, `static_line_y = int(330 * scale_y)`; the counter is built with `line_x_start=static_line_x_start, line_x_end=static_line_x_end` (`predict.py:729-732`). With the shipped calibration that is `384 … 934` in the 1280×720 analysis frame.
|
||||
|
||||
**Why:** `build_static_roi` ALREADY computes the calibrated count-line x-window (`line_x_start = int(count_line.get("x_start", x1) * sx)`, `line_x_end = int(count_line.get("x_end", x2) * sx)` — `src/zone_config.py`) and then DISCARDS it, because `TruckROI` has no such fields. The runners therefore fall back to the truck-ROI bounds (`counter.line_x_start = roi.x1`, `counter.line_x_end = roi.x2` → `400 … 936` with the shipped preset). FCP counts crossings inside `384 … 934`. Same clip, different window → different counts at the edges.
|
||||
|
||||
- [ ] **Step 1: Write the failing tests** — in `tests/test_zone_config.py`:
|
||||
|
||||
```python
|
||||
def test_build_static_roi_carries_the_count_line_x_window():
|
||||
"""The calibrated count-line x-window survives the ROI build (FCP predict.py:701)."""
|
||||
zone = {"truck_area": [[600, 385], [609, 1076], [1404, 1078], [1381, 343]],
|
||||
"count_line": {"x_start": 577, "x_end": 1401, "y": 330},
|
||||
"reference_resolution": [1920, 1080]}
|
||||
roi = build_static_roi(zone, 1280, 720)
|
||||
assert roi.line_x_start == 384 # int(577 * 1280/1920)
|
||||
assert roi.line_x_end == 934 # int(1401 * 1280/1920)
|
||||
assert roi.line_y == 220 # int(330 * 720/1080)
|
||||
```
|
||||
|
||||
and in `tests/test_pipeline.py`: drive a runner with a `fixed_zone` whose `line_x_start`/`line_x_end` DIFFER from `x1`/`x2` and assert the counter ended up with the count-line window (it must fail if the runners still use `roi.x1` / `roi.x2`).
|
||||
|
||||
- [ ] **Step 2: Run the tests to verify they fail**
|
||||
|
||||
Run: `python -m pytest tests/test_zone_config.py tests/test_pipeline.py -k "count_line or x_window" -v`
|
||||
Expected: FAIL — `TruckROI` has no `line_x_start`.
|
||||
|
||||
- [ ] **Step 3: Implement**
|
||||
- `src/truck_roi.py`: add `line_x_start: int | None = None` and `line_x_end: int | None = None` to `TruckROI` (defaults, so every existing construction keeps working).
|
||||
- `src/zone_config.py`: `build_static_roi` passes the already-computed `line_x_start` / `line_x_end` into the `TruckROI` it returns. A zone without `count_line` keeps `None` (the auto-detected path in `TruckROITracker` is untouched).
|
||||
- `src/pipeline.py`: in BOTH runners, where the counter's window is set from the ROI, use the ROI's count-line window when it has one: `counter.line_x_start = roi.line_x_start if roi.line_x_start is not None else roi.x1` (same for `line_x_end`).
|
||||
|
||||
- [ ] **Step 4: Run the tests to verify they pass**
|
||||
|
||||
Run: `python -m pytest tests/test_zone_config.py tests/test_pipeline.py -v` → all pass. Then `python -m pytest tests/ -q` → zero failures.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add src/truck_roi.py src/zone_config.py src/pipeline.py tests/test_zone_config.py tests/test_pipeline.py
|
||||
git commit -m "fix: count inside FCP's calibrated count-line x-window (predict.py:701 parity)"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Out of Scope (deliberately not ported)
|
||||
|
||||
| FCP feature | Why not |
|
||||
@@ -939,7 +999,7 @@ git commit -m "feat: flag truncated clips in the job result"
|
||||
|
||||
## Verification
|
||||
|
||||
1. **Unit suite**: `python -m pytest tests/ -q` → zero failures (baseline was 204 passed; new tests added in Tasks 0, 1, 3, 4, 5, 6, 7, 8, 9, 10).
|
||||
1. **Unit suite**: `python -m pytest tests/ -q` → zero failures (baseline was 204 passed; the branch adds tests in Tasks 0–3, 4, 5, 6, 7, 8, 9, 10, 11 — 296 passed at the end of the branch).
|
||||
2. **Calibration equality** (static geometry must match FCP exactly):
|
||||
```bash
|
||||
python - <<'PY'
|
||||
@@ -949,10 +1009,10 @@ git commit -m "feat: flag truncated clips in the job result"
|
||||
"counting_area": [[574,50],[586,1077],[1418,1076],[1397,50]],
|
||||
"reference_resolution": [1920,1080]}
|
||||
roi = build_static_roi(zone, 1280, 720)
|
||||
print(roi.line_y, roi.x1, roi.x2)
|
||||
print(roi.line_y, roi.x1, roi.x2, roi.line_x_start, roi.line_x_end)
|
||||
PY
|
||||
```
|
||||
Expected: `220 400 936` — identical to FCP `predict.py:701-719` (FCP's count-line x-range `384…934` is not carried by the recounter's `TruckROI`, which has no such fields).
|
||||
Expected: `220 400 936 384 934` — identical to FCP `predict.py:701-719` (the count-line x-window `384…934` is carried by the recounter's `TruckROI` since Task 11; the effective counting window is the ROI x-filter `400…936` ∩ the counter window `384…934` = `400…934` on both sides).
|
||||
3. **Frame and model input are pinned** (Task 0):
|
||||
```bash
|
||||
grep -n "imgsz=640" src/tracking.py src/detection.py
|
||||
|
||||
Reference in new issue
Block a user