docs: add ERD.md (Mermaid) and CHANGELOG.md
ERD: no DB in this repo — models in-memory Job/JobResult entities plus filesystem artifacts (uploads/, output/job-*/, zones.json, models/), with status state machine and restart/orphan hazards. CHANGELOG: Keep a Changelog format covering all 83 commits grouped by date, from 2026-09-15 init through the /upload NameError 500 fix.
This commit is contained in:
1 parent
8012f45a5c
commit
97507f8bf8
2 files changed
+363
No files matched your search
+191
@@ -0,0 +1,191 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project are documented here. Format follows
|
||||
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) (dated entries; no
|
||||
version tags are cut in this repo — `main` is the release line).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- **Upload 500 on new video + start analysis**: `/upload` referenced
|
||||
`video_path` in `probe_video(video_path)` before the variable was defined
|
||||
(`NameError` → Flask 500). Removed the duplicate premature height-check
|
||||
block; post-save `resize_video_to_max_height()` (720p) already covers it
|
||||
(`app.py:120-125`, `b1dd06e`).
|
||||
|
||||
### Changed
|
||||
- **Counting/tracking params mirrored from platform** (`karung_counter_semarang`):
|
||||
`stabilizer.max_hold_frames` 10 → **25** (~1 s occlusion hold),
|
||||
`cfg/tracker.yaml` `track_buffer` 60 → **90** (~3.6 s lost-track hold),
|
||||
`ByteTrackTracker` gained `iou=0.7` passed to `model.track()`.
|
||||
`src/stabilizer.py`, `src/tracking.py`, `cfg/tracker.yaml` now byte-identical
|
||||
to the platform (`37e2d3e`).
|
||||
- **Auto-resize uploads to 720p, 720p default output** — only transcoded when
|
||||
source is taller than 720p; default output height option set to 720p
|
||||
(`89a265c`).
|
||||
|
||||
### Added
|
||||
- Plan doc for fixed-zone mode (`.opencode/plans/fixed-zone-mode.md`).
|
||||
|
||||
## 2026-10-14 — Platform parity wave
|
||||
|
||||
### Added
|
||||
- **Re-attach orphaned output dirs after restart** (`d09800c`): jobs are
|
||||
in-memory; `JobQueue._register_orphans()` now re-attaches `output/job-*`
|
||||
older than 300 s as synthetic COMPLETED jobs so they stay deletable from
|
||||
the UI. Younger dirs skipped (may belong to a live process).
|
||||
- **`config.yaml` as single source of truth for tunables** (`7230e2b`):
|
||||
detection, `min_bbox_area`, `iou`, roi, stabilizer, pipeline blocks; code
|
||||
reads config instead of scattered constants.
|
||||
- **Start/stop/restart dashboard scripts** (`d89c985`):
|
||||
`start_dashboard.sh`, `stop_dashboard.sh`, `restart_dashboard.sh`.
|
||||
|
||||
### Fixed
|
||||
- **`min_bbox_area` scaled from platform's 1280x720 reference to actual
|
||||
frame size** (`c2d720e`) — hardcoded pixel area mis-scaled at other
|
||||
resolutions.
|
||||
- **"Waiting for first frame" placeholder** hidden once MJPEG delivers the
|
||||
first frame (`2efcdb2`).
|
||||
|
||||
### Changed
|
||||
- **Platform detection parity + progress bars** (`ce604b0`): detection
|
||||
behaviour matched to reference repo; download and processing progress bars
|
||||
on the UI.
|
||||
- **Async writer thread + MJPEG mtime guard** (`92fd4cb`): video encode off
|
||||
the pipeline thread; preview stream only re-sends when file mtime changes.
|
||||
|
||||
## 2026-09-30 — Accuracy defaults
|
||||
|
||||
### Fixed
|
||||
- **Restored accuracy defaults**: `detect_interval=1`, `sup_det_interval=5`
|
||||
(`31bfe7c`) — earlier throttling to every 2nd/10th frame had cost counts.
|
||||
|
||||
## 2026-09-29 — Fixed ROI + live box counts
|
||||
|
||||
### Added
|
||||
- **Fixed ROI zone mode as default selection** (`f2b5644`).
|
||||
- **Live box counts + separate sack/box nets on status page** (`81e6ae6`).
|
||||
- **Freeze ROI mode** with deadband+sticky jitter fix and explicit
|
||||
fixed/frozen ROI flags (`4bd9de5`).
|
||||
- **Stabilize secondary-model detections + box-wins suppression**; web UI
|
||||
moved to **port 9050** (`ad41bf0`).
|
||||
|
||||
### Changed
|
||||
- Tracker throttled to every 2nd frame, supplementary detector interval 10,
|
||||
720p output option (`07289a4`). *(Later partially rolled back by
|
||||
`31bfe7c` for accuracy.)*
|
||||
|
||||
## 2026-09-28 — Counting correctness + downloads
|
||||
|
||||
### Fixed
|
||||
- **Exclude `truck` class from counting; switch to `MultiClassLineCounter`
|
||||
with real class labels** (`d383759`) — trucks were inflating sack counts.
|
||||
- **Consistent `Sack In`/`Sack Out` labels** across live panel and result
|
||||
cards (`1dbfeca`).
|
||||
- **Atomic compression writes**, enforce 250 MB size limit, job status guard
|
||||
(`f878110`) — no more truncated `_compressed.mp4` on kill.
|
||||
- **Isolate tests from the real `output/` dir** via conftest autouse fixture
|
||||
(`9a276b2`).
|
||||
|
||||
### Added
|
||||
- **Compress downloads to max 250 MB via ffmpeg** with mtime-based cache
|
||||
(`6f86bca`).
|
||||
- **Propagate sack vs box counts to results and UI** (`7932119`).
|
||||
|
||||
## 2026-09-22 — Zones, merged pipeline, live preview
|
||||
|
||||
### Added
|
||||
- **Interactive zone calibration tool** (`859d6a0`).
|
||||
- **Zone config loader + static ROI builder** (`4ad4284`), `zone_mode` /
|
||||
`fixed_zone` fields on `Job` (`7c91081`), preset dropdown in the web UI
|
||||
(`f0ea95d`), visual distinction for fixed zone vs dynamic ROI (`2b46231`).
|
||||
- **Merged detection output + parallel model execution** (`fc20a52`).
|
||||
- **Live preview toggle, FPS indicator, live counting by object**
|
||||
(`09a8829`).
|
||||
- **Live preview switched from WebSocket to MJPEG streaming** (`a5566f3`)
|
||||
and 15+ FPS push groundwork (`f9e411f`).
|
||||
|
||||
### Fixed
|
||||
- **Use tracker for counting + throttle supplementary detectors**
|
||||
(`5bf44d6`) — detections without track IDs never reached the counter.
|
||||
- **Absolute `OUTPUT_DIR`, resolution scaling for zones**, full reference-repo
|
||||
values (`35cccd0`).
|
||||
- Toggle preview display bug, job deletion, pipeline optimizations
|
||||
(`1632800`).
|
||||
- Show live preview img by default (was `display:none` from SocketIO era)
|
||||
(`b6379e1`).
|
||||
|
||||
### Changed
|
||||
- Docs: README updated with current features and API (`39b582a`).
|
||||
|
||||
## 2026-09-21 — Job UX + resource management
|
||||
|
||||
### Added
|
||||
- **Video reuse**: re-analyze previous uploads without re-uploading
|
||||
(`f779f05`), delete button for uploaded videos (`d353272`).
|
||||
- **Abort button for job cancellation** (`6783ff3`).
|
||||
- **Video upload `required` attr removed** when an existing video is
|
||||
selected (`42c80fd`).
|
||||
|
||||
### Fixed
|
||||
- **Explicit GPU memory cleanup between models to prevent OOM**
|
||||
(`93daa68`).
|
||||
- **Pass truck centroid to batch manager** for state transitions
|
||||
(`1e28eb4`).
|
||||
- **Auto-use truck-detector when model lacks `truck` class** (`57afb62`).
|
||||
- **Pin `numpy<2.0`** to resolve Jetson torch incompatibility (`a75db4c`).
|
||||
|
||||
## 2026-09-18 — Grouped models + TensorRT
|
||||
|
||||
### Added
|
||||
- **`ModelGroup` + `scan_model_groups()`** for grouped model display
|
||||
(`22c7842`), grouped selection in JS (`d07b3ba`), grouped Flask routes
|
||||
(`dbd79ed`).
|
||||
- **TensorRT engine export script** (`d32045b`).
|
||||
|
||||
### Fixed
|
||||
- **Graceful error when `onnxruntime` is missing** for `.onnx` models
|
||||
(`06b013a`).
|
||||
- Removed duplicate `v4-best (1).pt` (`1bc5e06`).
|
||||
- Status page: flat progress bar, `created_at` formatting (`47ffede`);
|
||||
dynamic `aria-valuenow`, focus-visible styles (`7b19b5b`).
|
||||
|
||||
### UI wave (2026-09-17 → 09-18)
|
||||
- Design system foundation, CSS tokens, base template (`fbcff78`,
|
||||
`c17d480`).
|
||||
- Upload page: drag-drop, video preview, model cards (`f245e94`); double-toggle
|
||||
bug + hardcoded colors (`197c505`).
|
||||
- Status page: progress bar, live preview, result cards, polling (`1c54bb1`);
|
||||
null safety + connection-lost handling (`6323583`, `1d35c28`).
|
||||
- Jobs page: card grid with badges/thumbnails (`b1170f4`), semantic cards +
|
||||
flat progress bar (`20d5234`), accessibility/responsive polish (`441a6a8`).
|
||||
- Video preview endpoints: thumbnail, sample frames, live frame (`dca6f6b`).
|
||||
- Pipeline emits live annotated frames for preview (`f487b5c`); clears
|
||||
`latest_frame` on failure (`87c8da3`).
|
||||
|
||||
## 2026-09-16 — Initial working release
|
||||
|
||||
### Added
|
||||
- **Flask web UI on port 9000** with upload, job status, APIs (`eb77e5b`).
|
||||
- **CLI entry point**: `--video`, `--model`, `--filter`, `--list-models`
|
||||
(`f38c970`).
|
||||
- **Async job queue** — thread-safe add/get/cancel/list (`e13926d`).
|
||||
- **Pipeline runner** processing video through the counting pipeline
|
||||
(`5a04cc5`); annotated video writer wrapping OpenCV (`61c9868`).
|
||||
- **Model registry** scanning `models/` with known-class map (`f5982a4`).
|
||||
- **Core pipeline modules copied from `karung_counter_semarang`**
|
||||
(`71c1ae1`).
|
||||
- Integration tests for Flask routes (`05bdac5`); complete README with usage,
|
||||
CLI, API reference (`1377fbb`).
|
||||
|
||||
### Fixed
|
||||
- Secure upload/download paths, default filter, status enum compare, upload
|
||||
validation (`40e2dbe`).
|
||||
- Final review wave: CLI kwargs, class filter, job locks, upload order
|
||||
(`2b54cc3`).
|
||||
- Relax racy `PENDING` assertion in `test_queue_add_job` (`f14f3b5`).
|
||||
|
||||
## 2026-09-15 — Project init
|
||||
|
||||
- Project structure and skeleton with `pyproject.toml`, `config.yaml`,
|
||||
`cfg/tracker.yaml`, README (`43a959d`, `927c84d`, `7fb0174`).
|
||||
@@ -0,0 +1,172 @@
|
||||
# ERD — Feedmill Recounter
|
||||
|
||||
Data model for the feedmill recounter. **No database** — jobs live in
|
||||
memory (`JobQueue._jobs` dict, `src/job.py:82`) and die on restart; state
|
||||
survives only as filesystem artifacts under `$OUTPUT_DIR` (env override
|
||||
`OUTPUT_DIR`, default `./output`) and `$UPLOAD_DIR` (default `./uploads`).
|
||||
|
||||
**No foreign keys enforced** — every reference is soft: job stores plain
|
||||
string paths, zone presets are name strings, model stems are dict keys.
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
upload_video ||--o{ job : "re-analyze, N runs per file"
|
||||
model_group ||--o{ job_result : "selected format runs as"
|
||||
zone_preset ||--o{ job : "soft name ref, zone_mode=fixed"
|
||||
job ||--o{ job_result : "1 for single model, 1 merged row for many"
|
||||
job ||--|| output_dir : "1:1, output/job-"
|
||||
output_dir ||--o{ result_file : "written on completion"
|
||||
output_dir ||--o{ sample_frame : "lazy thumbnail/sample cache"
|
||||
upload_video ||--o{ upload_video : "same name re-upload, _N suffix"
|
||||
|
||||
job {
|
||||
TEXT job_id PK "job-<uuid4[:8]>, in-memory only"
|
||||
TEXT video_path "abs/rel path under uploads/"
|
||||
TEXT status "PENDING | RUNNING | COMPLETED | FAILED | CANCELLED"
|
||||
FLOAT progress "0.0 - 1.0"
|
||||
TEXT current_model "label while running"
|
||||
TEXT zone_mode "dynamic | freeze | fixed"
|
||||
TEXT zone_preset "name in zones.json, '' if dynamic"
|
||||
BLOB fixed_zone "TruckROI | None, built at submit time"
|
||||
INT output_max_height "transcode cap, None = source height"
|
||||
TEXT preview_path "/tmp/feedmill_preview_<job_id>.jpg"
|
||||
INT live_fps "MJPEG live stats"
|
||||
INT live_loading "MJPEG live stats"
|
||||
INT live_unloading "MJPEG live stats"
|
||||
INT live_box_loading "MJPEG live stats"
|
||||
INT live_box_unloading "MJPEG live stats"
|
||||
TEXT error "exception str when FAILED"
|
||||
TIMESTAMP created_at "default time.time()"
|
||||
TIMESTAMP completed_at "NULL while running"
|
||||
}
|
||||
|
||||
job_result {
|
||||
TEXT model_name PK "filename, or 'Merged (a, b, c)'"
|
||||
TEXT output_path "video path under output/job-*/"
|
||||
INT loading_count "sack loading (crossing events)"
|
||||
INT unloading_count "sack unloading"
|
||||
INT net_count "loading - unloading"
|
||||
INT box_loading_count "box loading"
|
||||
INT box_unloading_count "box unloading"
|
||||
INT box_net_count "box_loading - box_unloading"
|
||||
INT batch_count "BatchManager state transitions"
|
||||
INT frame_count "frames processed"
|
||||
FLOAT duration_seconds "wall clock of pipeline run"
|
||||
TEXT error "per-model failure, nullable"
|
||||
}
|
||||
|
||||
model_group {
|
||||
TEXT stem PK "filename stem, shared across formats"
|
||||
TEXT formats "list: .engine > .pt > .onnx preference"
|
||||
TEXT format_paths "dict ext -> resolved path"
|
||||
TEXT known_classes "sack / truck / box / person"
|
||||
TEXT default_format "engine if present"
|
||||
}
|
||||
|
||||
zone_preset {
|
||||
TEXT name PK "key under zones.json presets"
|
||||
FLOATS polygon "TruckROI points, video-pixel space"
|
||||
BOOL active "matches zones.json active_preset"
|
||||
}
|
||||
|
||||
upload_video {
|
||||
TEXT path PK "uploads/<unique-filename>"
|
||||
TEXT filename "original + _N on collision"
|
||||
INT size_bytes "stat().st_size"
|
||||
TIMESTAMP mtime "sort key in /api/videos"
|
||||
INT height "source height, >720 triggers transcode"
|
||||
}
|
||||
|
||||
output_dir {
|
||||
TEXT job_id PK "output/job-<id>"
|
||||
TIMESTAMP mtime "orphan re-attach threshold, 300s"
|
||||
BOOL orphan "register_orphans re-attaches age>300s"
|
||||
}
|
||||
|
||||
result_file {
|
||||
TEXT filename PK "within output/job-*/"
|
||||
TEXT kind "annotated.mp4 | thumbnail.jpg | predictions.csv"
|
||||
INT size_bytes "download compression kicks in >250MB"
|
||||
}
|
||||
|
||||
sample_frame {
|
||||
TEXT path PK "output/job-*/samples/frame_N.jpg"
|
||||
TEXT cache_marker "samples/.cached = newline list of paths"
|
||||
}
|
||||
```
|
||||
|
||||
## Keys
|
||||
|
||||
- `job.job_id`: generated `job-{uuid4().hex[:8]}` (`src/job.py:125`); not
|
||||
stable across restarts — jobs are never reloaded, only their output dirs.
|
||||
- `model_group.stem`: implicit key over `models/` files sharing a stem.
|
||||
- `zone_preset.name`: key of `zones.json` → `presets[]`.
|
||||
- `output_dir.job_id`: directory name equals `job.job_id`.
|
||||
|
||||
## Relationships (logical)
|
||||
|
||||
| From | To | How |
|
||||
|---|---|---|
|
||||
| `job` → `upload_video` | N—1 | `job.video_path` string; `/upload/reuse` re-queues same file. |
|
||||
| `job` → `job_result` | 1—N | Single model → 1 `JobResult`; many models → 1 merged row (`src/job.py:308`). |
|
||||
| `job_result` → `model_group` | N—1 | `JobResult.model_name` = `ModelConfig.filename`; stem links to `ModelGroup`. |
|
||||
| `job` → `zone_preset` | N—1 | Soft: `zone_preset` string + `zone_mode=fixed`; preset deleted → `fixed_zone` still embedded. |
|
||||
| `job` → `output_dir` | 1—1 | `output_dir = $OUTPUT_DIR/job_id`, created at `add_job` (`src/job.py:137`). |
|
||||
|
||||
## Job status state machine
|
||||
|
||||
```
|
||||
PENDING ──▶ RUNNING ──▶ COMPLETED
|
||||
│ ├──────▶ FAILED (exception in pipeline, job.error set)
|
||||
└──────────▶ CANCELLED (api_cancel_job; worker checks in cancel_check)
|
||||
```
|
||||
|
||||
- `delete_job` only accepts `COMPLETED | FAILED | CANCELLED` (`src/job.py:179`).
|
||||
- Worker clears `latest_frame` on any terminal state; preview file removed in
|
||||
`finally` (`src/job.py:335`).
|
||||
|
||||
## Storage layout (filesystem, not SQLite)
|
||||
|
||||
| Path | Role |
|
||||
|---|---|
|
||||
| `$UPLOAD_DIR/<name>[_N].<ext>` | source videos; `secure_filename` + extension whitelist |
|
||||
| `$OUTPUT_DIR/job-<id>/` | per-job output: annotated mp4, `thumbnail.jpg`, `samples/`, `predictions.csv` |
|
||||
| `$OUTPUT_DIR/job-<id>/samples/.cached` | newline list of extracted sample frame paths |
|
||||
| `/tmp/feedmill_preview_<id>.jpg` | live MJPEG frame, deleted in worker `finally` |
|
||||
| `$OUTPUT_DIR/*_compressed.mp4` | ffmpeg download cache, invalidated by mtime vs source |
|
||||
| `zones.json` | `presets[]` + `active_preset`, geometry only |
|
||||
| `models/<stem>.{engine,pt,onnx}` | weight files grouped by stem |
|
||||
| `config.yaml` | single source of truth for tunables (detection, roi, stabilizer, pipeline) |
|
||||
|
||||
## Derived values
|
||||
|
||||
- `net_count = loading_count − unloading_count`,
|
||||
`box_net_count = box_loading_count − box_unloading_count`.
|
||||
- `progress` set to `1.0` only on terminal success; FAILED rows keep the last
|
||||
partial value.
|
||||
- Upload height: source `>720p` is transcoded to 720p before queueing
|
||||
(`app.py` `/upload`), so `upload_video.height` is pre-transcode.
|
||||
|
||||
## Hazards
|
||||
|
||||
- **Jobs are volatile**: restart loses all `Job` objects — only
|
||||
`output/job-*` dirs survive. `_register_orphans` (age > 300 s) re-attaches
|
||||
them as synthetic `COMPLETED` jobs with `video_path=""` so they stay
|
||||
deletable from the UI (`src/job.py:88`). Younger dirs are skipped because
|
||||
they may belong to a process still running.
|
||||
- **`video_path=""` on orphans**: thumbnail/sample endpoints on a restarted
|
||||
job cannot regenerate from source; they 404 once cache is missing.
|
||||
- **Soft zone ref**: deleting a preset from `zones.json` does not invalidate
|
||||
jobs already holding an embedded `fixed_zone` — geometry was snapshotted at
|
||||
submit time.
|
||||
- **Preview path in `/tmp`**: two jobs in one process never collide
|
||||
(`job_id` in filename), but stale files survive a hard kill until the next
|
||||
`delete_job`/`finally` runs.
|
||||
|
||||
## Sources
|
||||
|
||||
- Entity defs: `src/job.py:27-73` (`JobResult`, `Job`),
|
||||
`src/model_registry.py:22-34` (`ModelConfig`, `ModelGroup`).
|
||||
- Lifecycle: `src/job.py:114-148` (`add_job`), `src/job.py:203-343`
|
||||
(`_run_job`), `src/job.py:88-112` (`_register_orphans`).
|
||||
- HTTP surface: `app.py:110-209` (upload/reuse), `app.py:317-471` (APIs).
|
||||
Reference in new issue
Block a user