feat: add engine auto-recompilation, mortality detection, multi-execution batching, and dashboard updates
- Add engine_utils for TensorRT compatibility verification, auto-recompilation from .pt models, and YAML auto-updates - Add mortality detection pipeline (mortality.py, test_run_mortality.sh, mortality_config.yaml) - Add multi-execution batch modes (parallel_processes, tensor_batching, hybrid) in batch_runner.py - Add daily test run automation scripts and video processing runners - Add dashboard REST API, live stream endpoints, and web UI templates - Clean up git tracking by ignoring __pycache__, .pyc, and build artifacts
This commit is contained in:
1 parent
c05f3d98d0
commit
010f6e1493
97 files changed
+3361
-643
No files matched your search
@@ -47,12 +47,16 @@ src/chicken_counter/
|
||||
## Install
|
||||
|
||||
```bash
|
||||
python -m pip install -e .
|
||||
python3 -m venv venv
|
||||
venv/bin/pip install --upgrade pip
|
||||
venv/bin/pip install -r requirements.txt
|
||||
```
|
||||
|
||||
For Jetson deployment you will usually want a Jetson-compatible OpenCV and PyTorch
|
||||
stack already installed, then install the rest of the package around that environment.
|
||||
|
||||
> **Tip:** See `RUN.md` for a full step-by-step quickstart guide for new developers.
|
||||
|
||||
## Run
|
||||
|
||||
Update `configs/cameras/example_camera.yaml` with:
|
||||
@@ -199,7 +203,9 @@ detection:
|
||||
imgsz: 640 # keep 640 while using existing TensorRT .engine
|
||||
```
|
||||
|
||||
`configs/cycle7_batch.yaml` already uses these production defaults.
|
||||
`configs/cycle7_batch.yaml` and `configs/cycle7_batch_optimized.yaml` already use these production defaults.
|
||||
|
||||
`configs/cycle7_batch_optimized.yaml` adds per-camera parallelism, trimmed inference settings, and optimized YAML structure for the Sukawarna enclosure.
|
||||
|
||||
**Validation:** run a short clip with stride enabled, then compare `total_entered` against
|
||||
`inference_stride: 1` and `motion.stride_frames: 1`. Watch checkpoint `fps=` logs for
|
||||
@@ -217,6 +223,39 @@ for tuning.
|
||||
- The optical-flow trigger is vision-first, though the config structure leaves room for
|
||||
a future controller/encoder integration path
|
||||
|
||||
## Multi-Stage Growth Cycles & Day 0 Configuration
|
||||
|
||||
The pipeline dynamically adjusts detection and ROI entry thresholds based on flock age (Days Old Chick / DOC vs Mid-Cycle):
|
||||
|
||||
- **Day 0 (`cycle_start_date`)**: Configured in `configs/cycle7_batch_optimized.yaml` (default: `"2026-05-22"`). Can be overridden via CLI (`--cycle-start-date YYYY-MM-DD`) or REST API (`/api/config/cycle_start_date`).
|
||||
- **`early_cycle` (Days 0–15)**: Automatically applies high-sensitivity detection thresholds (`conf: 0.12`, `min_box_area_px: 200`, `min_overlap_ratio: 0.25`) for small fast-moving DOC chicks.
|
||||
- **`mid_cycle` (Days 16+)**: Preserves standard tuned per-camera defaults (`conf: 0.35–0.50`, `min_box_area_px: 2500–3000`).
|
||||
|
||||
## Mortality Detection
|
||||
|
||||
A separate pipeline detects carcasses (dead birds) from still photos. Supports multi-image daily runs and date subfolders (`mortality/YYYY-MM-DD/`).
|
||||
|
||||
```bash
|
||||
# Run on default mortality directory
|
||||
./test_run_mortality.sh
|
||||
|
||||
# Run on a specific date (auto-creates/routes to mortality/2026-05-23/)
|
||||
chicken-counter mortality --date 2026-05-23
|
||||
```
|
||||
|
||||
Key features:
|
||||
- **Multi-Image & Multi-Day Support**: Processes multiple images per day (e.g. morning/afternoon scans), aggregates the grand total carcass count (`total_mortality_count`), and saves outputs into date-isolated directories.
|
||||
- **2-Pass Detect & Refine**: runs the YOLO segmentation model once to find candidate regions, then uses `cv2.matchTemplate` to do a similarity search over each candidate before confirming it as a detection. This reduces false positives significantly.
|
||||
- **Containment filtering**: boxes where `IoA > 0.50` against a larger box are suppressed.
|
||||
- **Centroid deduplication**: detections whose centroids are within `dedupe_radius_px` of each other are merged to prevent counting the same carcass twice.
|
||||
- Uses the **segmentation model** (`models/chicken-detection-model-v26n-seg-300e-best-2026-04-18.pt`) which provides higher boundary precision than the standard detection model.
|
||||
|
||||
Outputs for each daily run:
|
||||
- `output_<name>.jpg` — annotated images with bounding boxes and carcass IDs
|
||||
- `mortality_report.json` — full summary report with `total_mortality_count`, per-image breakdown, and detection coordinates
|
||||
|
||||
Config: `configs/mortality_config.yaml`
|
||||
|
||||
## Headless Jetson MP4 Example
|
||||
|
||||
For a headless run that saves both output video and periodic checkpoint images, use a
|
||||
@@ -255,7 +294,7 @@ motion:
|
||||
flow_scale: 0.5
|
||||
display:
|
||||
show_window: false
|
||||
output_path: /media/jetson/DATA/try-sukawarna-vis.mp4
|
||||
output_path: /home/asus/.Codes/try-sukawarna-vis.mp4
|
||||
encoder: auto
|
||||
output_bitrate_kbps: 4000
|
||||
performance:
|
||||
@@ -294,14 +333,15 @@ For everyday processing of 4 cameras, use `configs/cycle7_batch.yaml`.
|
||||
|
||||
### Input folder layout
|
||||
|
||||
Place today's videos under:
|
||||
Place today's videos in a `VIDEOS` folder **adjacent to the project directory** (i.e. `../VIDEOS` relative to the project root):
|
||||
|
||||
```text
|
||||
/media/jetson/DATA/chicken-sukawarna/cycle7/2026-07-09/
|
||||
kandang_1_camera_1_2026-07-09_120056.mp4
|
||||
kandang_1_camera_2_2026-07-09_120456.mp4
|
||||
kandang_1_camera_3_2026-07-09_121012.mp4
|
||||
kandang_1_camera_4_2026-07-09_121530.mp4
|
||||
../VIDEOS/cycle7/kandang-atas/
|
||||
2026-06-18/
|
||||
kandang_1_camera_1_2026-06-18_120056.mp4
|
||||
kandang_1_camera_2_2026-06-18_120456.mp4
|
||||
kandang_1_camera_3_2026-06-18_121012.mp4
|
||||
kandang_1_camera_4_2026-06-18_121530.mp4
|
||||
```
|
||||
|
||||
Date folders use `YYYY-MM-DD`. Camera files are matched by `camera_num` using the
|
||||
@@ -310,13 +350,32 @@ pattern `kandang_*_camera_{num}_*.mp4`.
|
||||
### Run commands
|
||||
|
||||
```bash
|
||||
# Process today's folder
|
||||
chicken-counter batch --config configs/cycle7_batch.yaml
|
||||
# Process today's folder using default parallel process mode
|
||||
chicken-counter batch --config configs/cycle7_batch_optimized.yaml
|
||||
|
||||
# Process a specific date
|
||||
chicken-counter batch --config configs/cycle7_batch.yaml --date 2026-07-09
|
||||
# Process a specific date using Model-Level Tensor Batching mode
|
||||
chicken-counter batch --config configs/cycle7_batch_optimized.yaml --date 2026-06-18 --mode tensor_batching
|
||||
|
||||
# Process a specific date using Hybrid mode (Threaded CPU + Batched GPU)
|
||||
chicken-counter batch --config configs/cycle7_batch_optimized.yaml --date 2026-06-18 --mode hybrid
|
||||
|
||||
# Run automated batch script for Tensor Batching
|
||||
./test_run_tensor_batch.sh # Runs all dates (2026-06-10 to 2026-06-19)
|
||||
./test_run_tensor_batch.sh 2026-06-18 # Runs a specific date
|
||||
|
||||
# Run automated batch script for Hybrid execution mode
|
||||
./test_run_hybrid.sh # Runs all dates (2026-06-10 to 2026-06-19)
|
||||
./test_run_hybrid.sh 2026-06-18 # Runs a specific date
|
||||
```
|
||||
|
||||
### Execution Modes (`execution_mode`)
|
||||
|
||||
Set `batch.execution_mode` in `configs/cycle7_batch_optimized.yaml` or override via `--mode`:
|
||||
|
||||
- `parallel_processes` (Default): Runs cameras in separate OS processes (e.g. via `test_run.sh`).
|
||||
- `tensor_batching`: Synchronizes camera frame streams and executes a single batched GPU model inference pass across all cameras (`batch_size=N`).
|
||||
- `hybrid`: Combines multi-threaded CPU frame capture, optical flow, and rendering across CPU cores with a single synchronized batched GPU forward pass (`batch_size=N`).
|
||||
|
||||
Single-camera mode still works:
|
||||
|
||||
```bash
|
||||
@@ -327,7 +386,7 @@ chicken-counter run --config configs/cameras/example_camera.yaml
|
||||
### Output layout
|
||||
|
||||
```text
|
||||
/media/jetson/DATA/chicken-sukawarna/cycle7/2026-07-09/output/
|
||||
../VIDEOS/cycle7/kandang-atas/2026-06-18/output/
|
||||
CC1_vis.mp4
|
||||
CC1_compressed.mp4
|
||||
CC2_vis.mp4
|
||||
@@ -335,7 +394,7 @@ chicken-counter run --config configs/cameras/example_camera.yaml
|
||||
...
|
||||
checkpoints/CC1/frame_003000.jpg
|
||||
checkpoints/CC2/frame_006000.jpg
|
||||
counts_2026-07-09.json
|
||||
counts_2026-06-18.json
|
||||
```
|
||||
|
||||
After all 4 cameras finish counting, the batch runner compresses each annotated video
|
||||
@@ -384,11 +443,37 @@ For a ~72k frame run that is about 24 images per camera.
|
||||
### Cron example
|
||||
|
||||
```cron
|
||||
0 7 * * * cd /media/jetson/DATA/chicken-sukawarna && /usr/bin/chicken-counter batch --config configs/cycle7_batch.yaml >> logs/cycle7-batch.log 2>&1
|
||||
0 7 * * * cd /path/to/chicken-counting-sukawarna-det && ./test_run.sh >> logs/cycle7-batch.log 2>&1
|
||||
```
|
||||
|
||||
Requires `ffmpeg` on the Jetson PATH for post-run compression.
|
||||
|
||||
## Dashboard & API
|
||||
|
||||
Start the live dashboard and API server:
|
||||
|
||||
```bash
|
||||
# Portable launcher (recommended) — auto-discovers mortality dir
|
||||
./start_dashboard.sh
|
||||
|
||||
# Or start manually
|
||||
PYTHONPATH=src venv/bin/python dashboard.py \
|
||||
--port 8080 \
|
||||
--db db/chicken_counts.db \
|
||||
--mortality-dir ../VIDEOS/cycle7/kandang-atas/mortality
|
||||
```
|
||||
|
||||
Key API endpoints (see `API.md` for full schema):
|
||||
|
||||
| Endpoint | Description |
|
||||
| :--- | :--- |
|
||||
| `GET /api/db/summary` | Lifetime totals across all dates |
|
||||
| `GET /api/db/history` | Per-date summary, newest first |
|
||||
| `GET /api/db/date/<YYYY-MM-DD>` | Per-camera breakdown for a date |
|
||||
| `GET /api/mortality/latest` | Latest carcass detection report |
|
||||
| `GET /api/mortality/history` | All mortality reports, newest first |
|
||||
| `GET /api/mortality/image/<name>` | Serve annotated output JPEG |
|
||||
|
||||
## Next Jetson-Focused Improvements
|
||||
|
||||
1. Add a hardware-aware video ingest path for CSI/GStreamer.
|
||||
@@ -397,4 +482,5 @@ Requires `ffmpeg` on the Jetson PATH for post-run compression.
|
||||
|
||||
Recent work includes daily 4-camera batch processing, JSON count reports, post-run
|
||||
compression under 200 MB, GStreamer hardware encoding, overlay buffer reuse,
|
||||
duplicate optical-flow removal (`gmc_method: none`), and long-run ETA logging.
|
||||
duplicate optical-flow removal (`gmc_method: none`), long-run ETA logging, mortality
|
||||
2-pass detection with feature similarity search, and a REST API via `dashboard.py`.
|
||||
Reference in new issue
Block a user