docs: changelog and plan for the batch-lifecycle parity wave
Plan: add Task 12 (a broken zone calibration degrades instead of publishing a wrong count) and Task 13 (FCP's batch lifecycle — count every frame, the FSM's arguments, a real truck signal), update the file structure and the verification steps, and record the two remaining gaps as out of scope (the dynamic-mode counting line, the truncated flag in the UI). CHANGELOG: the batch-lifecycle change (published counts and batch_count can change for every clip), the zone-calibration hardening and the review-wave fixes.
This commit is contained in:
1 parent
59d8c5521d
commit
82896969d6
2 files changed
+121
-9
No files matched your search
@@ -40,6 +40,29 @@ version tags are cut in this repo — `main` is the release line).
|
||||
filename fallback for legacy callers).
|
||||
|
||||
### Changed
|
||||
- **Batch lifecycle now matches FCP's** (`1c313d9`, `59d8c55`): the line
|
||||
counter is fed on **every** frame (FCP `predict.py:1066-1067` — it used to
|
||||
run only while a batch was open, so crossings before the batch opened were
|
||||
never counted), the batch FSM is built with FCP's arguments
|
||||
(`predict.py:739-745`: stabilize 0 s, threshold disabled, idle timeout 20 s,
|
||||
min duration 5 s, truck-gone tolerance 30 s), and the truck model now runs
|
||||
in fixed-zone mode too (`predict.py:882`) so the batch's truck signal is a
|
||||
real detection inside the counting area (`predict.py:893-902`) instead of
|
||||
the static zone's constant confidence.
|
||||
**Consequence: published counts can change for every clip** — crossings
|
||||
before the first batch opens now count, and `batch_count` reflects the real
|
||||
truck sessions instead of always being `0` in fixed-zone mode.
|
||||
- **A broken zone calibration degrades instead of publishing a wrong count**
|
||||
(`2ca4cb6`): a `truck_area` with a malformed point, a missing or short
|
||||
`truck_area`, or a degenerate (zero-area) counting polygon now drops the
|
||||
job back to dynamic mode instead of raising a 500, inventing a heuristic
|
||||
ROI, or filtering every detection away (which reported zero sacks).
|
||||
- **Review-wave hardening** (`76b902d`): a `count_line` without
|
||||
`x_start`/`x_end`/`y` no longer scales the fallback twice (the counting
|
||||
window moved to `266...624` instead of `400...936`); a broken `config.yaml`
|
||||
answers JSON 400 on `POST /api/analyze` instead of a 500 HTML page; a job
|
||||
created with `zone_mode=fixed` but no calibrated ROI is labelled
|
||||
`dynamic`, because that is what it counts against.
|
||||
- **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**
|
||||
|
||||
@@ -65,17 +65,17 @@ 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), 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/zone_config.py` — expose counting-area + truck-area polygons (Task 3, 6), carry the calibrated count-line x-window (Task 11), reject a broken calibration (Task 12).
|
||||
- `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), FCP's batch lifecycle + a real truck signal (Task 13).
|
||||
- `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/config.py` — fail-fast load + validation call (Task 9), FCP's batch arguments (Task 13).
|
||||
- `src/job.py` — `JobResult.truncated` / `frames_expected` (Task 10), truthful `zone_mode` (Task 12 review wave).
|
||||
- `src/truck_roi.py` — optional `line_x_start` / `line_x_end` on `TruckROI` (Task 11).
|
||||
- `config.yaml` — parity values (Tasks 4, 5, 8).
|
||||
- `config.yaml` — parity values (Tasks 4, 5, 8), FCP's batch arguments (Task 13).
|
||||
- `src/tracking.py` — explicit `imgsz=640` (Task 0).
|
||||
- `src/detection.py` — explicit `imgsz=640` (Task 0).
|
||||
- `src/video_writer.py` — encodes the 1280×720 analysis frame (Task 0); no API change.
|
||||
- `app.py` — zone ROI built in the 1280×720 frame (Task 0), `zone_mode` default (Task 2), truncation fields in the job response (Task 10).
|
||||
- `app.py` — zone ROI built in the 1280×720 frame (Task 0), `zone_mode` default (Task 2), truncation fields in the job response (Task 10), the zone guard (Task 12), JSON errors for a broken config (Task 9 review wave).
|
||||
|
||||
**Create**
|
||||
- `src/validation.py` — `validate_config()` + `InputValidator` mirroring FCP `src/validation.py` (Task 9).
|
||||
@@ -982,6 +982,81 @@ git commit -m "fix: count inside FCP's calibrated count-line x-window (predict.p
|
||||
|
||||
---
|
||||
|
||||
### Task 12: Degrade a broken zone calibration instead of publishing a wrong count
|
||||
|
||||
> Added after the whole-branch review. A broken `zones.json` must never reach a
|
||||
> published count.
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/zone_config.py` (`build_static_roi`, `_build_polygon`)
|
||||
- Modify: `app.py` (the zone guard)
|
||||
- Test: `tests/test_zone_config.py`, `tests/test_app.py`
|
||||
|
||||
**What was wrong:**
|
||||
- `build_static_roi` indexed the `truck_area` points directly: a 1-element point raised
|
||||
`IndexError` and an infinite coordinate raised `OverflowError` — neither was in the
|
||||
app's guard tuple, so both became an HTTP 500.
|
||||
- A missing or short `truck_area` fell back to an invented heuristic box
|
||||
(`0.3w…0.75w`), still published as a calibrated "fixed" zone.
|
||||
- A degenerate (zero-area) counting polygon was built successfully and filtered out
|
||||
every detection — a clip with a valid-looking zone reported **zero** sacks.
|
||||
|
||||
**Changes:**
|
||||
- `build_static_roi` reuses `_scaled_points` and raises `ValueError` when the
|
||||
`truck_area` is missing or malformed — the app's guard already handles `ValueError`
|
||||
and degrades to dynamic mode.
|
||||
- `_build_polygon` returns `None` for a zero-area polygon (treated as a malformed
|
||||
calibration, like every other malformed zone).
|
||||
- The app's guard also catches `IndexError`, `KeyError` and `OverflowError`.
|
||||
|
||||
**Commits:** `2ca4cb6`.
|
||||
|
||||
---
|
||||
|
||||
### Task 13: Batch-lifecycle parity with FCP's auto mode
|
||||
|
||||
> Added after the whole-branch review. FCP is the counting reference; every value
|
||||
> below is pinned to an FCP `file:line`.
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/pipeline.py` (both runners)
|
||||
- Modify: `src/config.py` (`DEFAULTS` — new `batch` section)
|
||||
- Modify: `config.yaml` (new `batch` section)
|
||||
- Test: `tests/test_pipeline.py`, `tests/test_config.py`
|
||||
|
||||
**What was wrong (three gaps):**
|
||||
1. The counter was only fed while a batch was open (`if batch_mgr.is_active:`), so a
|
||||
crossing that happened before the batch opened was **never counted**. FCP's auto
|
||||
mode counts on every frame (`predict.py:1066-1067`).
|
||||
2. The recounter built FCP's `BatchLifecycleManager` with the class DEFAULTS, not with
|
||||
FCP's arguments (`predict.py:739-745`) — every parameter differed.
|
||||
3. In fixed mode the recounter never ran the truck detector, so the FSM's truck signal
|
||||
was the static ROI's constant `confidence=1.0`: a batch opened on frame 1 (even
|
||||
with an empty scene) and never closed → `batch_count` was 0 on every fixed-mode
|
||||
clip.
|
||||
|
||||
**Changes:**
|
||||
- The track → stabilize → count block runs on **every** frame in both runners
|
||||
(FCP `predict.py:1066-1067`).
|
||||
- `build_batch_manager(cfg)` constructs the FSM with FCP's arguments
|
||||
(`predict.py:739-745`): `stabilize_seconds=0.0`, `stabilize_threshold_px=9999.0`,
|
||||
`sack_idle_timeout=cfg["batch"]["timeout_seconds"]` (20.0, FCP `config.yaml:123`),
|
||||
`min_batch_duration=5.0`, `truck_gone_tolerance=cfg["batch"]
|
||||
["truck_gone_tolerance_seconds"]` (30.0, FCP `config.yaml:124`).
|
||||
- The truck detector runs in **both** zone modes, on FCP's every-5-frames cadence
|
||||
(`predict.py:882`), and its result is cached in between. In fixed mode the FSM's
|
||||
truck signal is the real detection — a truck whose bbox overlaps the counting
|
||||
polygon by ≥50% (`predict.py:893-902`, `predict.py:964`) — while the calibrated ROI
|
||||
still provides the counting geometry.
|
||||
|
||||
**Commits:** `1c313d9`, `59d8c55`.
|
||||
|
||||
**Deliberately unchanged:** `src/batch.py` (the FSM class is FCP's already), the
|
||||
counter's predicates, the counting geometry, and the dynamic-mode counting-line
|
||||
defaults (still not FCP's — see Out of Scope).
|
||||
|
||||
---
|
||||
|
||||
## Out of Scope (deliberately not ported)
|
||||
|
||||
| FCP feature | Why not |
|
||||
@@ -994,12 +1069,14 @@ git commit -m "fix: count inside FCP's calibrated count-line x-window (predict.p
|
||||
| Load `.pt` before `.engine` (`predict.py:481-489`) | Speculative for us: the recounter already runs `.engine` models fine on the same Jetson. Revisit only if a TensorRT load ever fails on `.93`. |
|
||||
| `counting.confirm_delay_sec` / `exit_confirm_delay_sec` / `debounce_frames` / re-ID distance keys | Dead in FCP too — parsed, never read (`src/config_loader.py:637-662`). Porting them would add config with no behaviour. |
|
||||
| Cross-class IoU boundary: FCP keeps a sack when IoU `< 0.4` (`predict.py:946-948`), the recounter drops it only when IoU `> 0.4` (`src/pipeline.py:486`) | Differs at exactly IoU 0.400 — a measure-zero case with no measurable count effect. One-character fix if it ever shows up in a clip diff. |
|
||||
| Dynamic-mode counting line (`src/pipeline.py` `line_y=int(h*0.50)`, `line_x_start=int(w*0.38)`, `line_x_end=int(w*0.72)`) | FCP has no dynamic path — it always counts against the static calibration (`predict.py:715-724`). Dynamic mode stays recounter-specific; changing its line would silently move counts for existing dynamic-mode users. |
|
||||
| The `truncated` flag in the web UI | The flag is in the job result and in both API responses. A status-page badge is UI work, not counting logic. |
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
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).
|
||||
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, 12, 13 — 315 passed at the end of the branch).
|
||||
2. **Calibration equality** (static geometry must match FCP exactly):
|
||||
```bash
|
||||
python - <<'PY'
|
||||
@@ -1025,7 +1102,19 @@ git commit -m "fix: count inside FCP's calibrated count-line x-window (predict.p
|
||||
output/job-*/merged_annotated_*.mp4
|
||||
```
|
||||
Expected: `1280,720`.
|
||||
5. **Cross-check against FCP on one real clip** (read-only w.r.t. the FCP repo):
|
||||
5. **The batch FSM is FCP's** (Task 13):
|
||||
```bash
|
||||
python - <<'PY'
|
||||
from src.config import load_config
|
||||
from src.pipeline import build_batch_manager
|
||||
m = build_batch_manager(load_config())
|
||||
print(m._stabilize_seconds, m._stabilize_threshold_px, m._sack_idle_timeout,
|
||||
m._min_batch_duration, m._truck_gone_tolerance)
|
||||
PY
|
||||
```
|
||||
Expected: `0.0 9999.0 20.0 5.0 30.0` — FCP `predict.py:739-745` with
|
||||
`config.yaml:123-124`.
|
||||
6. **Cross-check against FCP on one real clip** (read-only w.r.t. the FCP repo):
|
||||
```bash
|
||||
rm -rf /tmp/fcp-parity && cp -r ../karung_counter_semarang /tmp/fcp-parity
|
||||
# run FCP on the clip (file source, not RTSP) from the copy
|
||||
@@ -1034,4 +1123,4 @@ git commit -m "fix: count inside FCP's calibrated count-line x-window (predict.p
|
||||
curl -F "fcp_mode=C" -F "video=@<clip.mp4>" http://127.0.0.1:9050/api/analyze
|
||||
```
|
||||
Expected: `loading_count` / `unloading_count` agree, or differ by at most the documented platform-only differences (FCP counts a live session per truck batch; the recounter counts the whole clip). Record the actual delta in the PR description.
|
||||
6. **Manual spot check**: play the annotated output of one clip and confirm the counted sacks are exactly the ones that crossed the calibrated line inside the counting polygon.
|
||||
7. **Manual spot check**: play the annotated output of one clip and confirm the counted sacks are exactly the ones that crossed the calibrated line inside the counting polygon.
|
||||
Reference in new issue
Block a user