feat: default port 8090 and multi-tier TensorRT model loading fail-safe

This commit is contained in:
andrew committed 2026-08-20 13:27:18 +07:00
1 parent 2dbb81226f
commit 862277acd3
11 files changed
+54 -20

No files matched your search

+4 -4
View File
@@ -1,6 +1,6 @@
# Chicken Counter API
Base URL: `http://<jetson-ip>:8080`
Base URL: `http://<jetson-ip>:8090`
## System Status & Live Monitoring
@@ -360,7 +360,7 @@ Optional environment variables:
| Variable | Default | Description |
| :--- | :--- | :--- |
| `PORT` | `8080` | Port to listen on |
| `PORT` | `8090` | Port to listen on |
| `DB_PATH` | `db/chicken_counts.db` | Path to SQLite database |
| `MORTALITY_DIRS` | auto-detected | Comma-separated mortality dirs |
@@ -368,7 +368,7 @@ Or start manually with full control:
```bash
PYTHONPATH=src venv/bin/python dashboard.py \
--port 8080 \
--port 8090 \
--db db/chicken_counts.db \
--mortality-dir /path/to/mortality \
--mortality-dir /path/to/another/mortality
@@ -381,7 +381,7 @@ PYTHONPATH=src venv/bin/python dashboard.py \
When integrating with external management systems or cloud backends, you can query status or send automated event notifications (e.g. `STARTED`, `COMPLETED`, `MORTALITY_DETECTED`).
### 1. Polling Pipeline State
External systems can poll `GET http://<jetson-ip>:8080/api/status` every 5–10 seconds to detect if counting or mortality runs are currently in progress or finished.
External systems can poll `GET http://<jetson-ip>:8090/api/status` every 5–10 seconds to detect if counting or mortality runs are currently in progress or finished.
### 2. Sending Outbound Webhook from Shell / Batch Scripts
To notify an external endpoint (e.g. `https://your-server.com/api/notify`) upon run lifecycle events:
+1 -1
View File
@@ -486,7 +486,7 @@ Start the live dashboard and API server:
# Or start manually
PYTHONPATH=src venv/bin/python dashboard.py \
--port 8080 \
--port 8090 \
--db db/chicken_counts.db \
--mortality-dir ../VIDEOS/cycle7/kandang-atas/mortality
```
+2 -2
View File
@@ -121,7 +121,7 @@ Output is saved in `../VIDEOS/cycle7/<coop>/<floor>/<date>/output/`.
#### Method 1: Stationary Inspection Camera Capture (Recommended for Farm Workers)
Each coop (or central mortality table) is equipped with a dedicated stationary camera (RTSP stream or USB camera) mounted above the inspection area:
1. **Open the Webapp**: From any phone, tablet, or terminal on the farm local network, navigate to `http://<JETSON-IP>:8080`.
1. **Open the Webapp**: From any phone, tablet, or terminal on the farm local network, navigate to `http://<JETSON-IP>:8090`.
2. **Open Mortality Inspector**: Under the sidebar **💀 Mortality Scans**, tap **`📷 Upload / Capture`**.
3. **Select Coop & Inspect View**:
- Choose the coop (e.g. `K1`).
@@ -196,7 +196,7 @@ PORT=9090 ./start_dashboard.sh
MORTALITY_DIRS="/path/to/mortality1,/path/to/mortality2" ./start_dashboard.sh
```
Open in browser: **http://localhost:8080**
Open in browser: **http://localhost:8090**
Available API endpoints:
+1 -1
View File
@@ -10,7 +10,7 @@ ExecStart=%h/.Codes/chicken-counting-sukawarna-det/start_dashboard.sh
Restart=always
RestartSec=5
Environment=PYTHONUNBUFFERED=1
Environment=PORT=8080
Environment=PORT=8090
[Install]
WantedBy=default.target
+1 -1
View File
@@ -37,7 +37,7 @@ class ThreadingHTTPServer(ThreadingMixIn, HTTPServer):
DEFAULT_SHM_DIR = "/dev/shm"
DEFAULT_PORT = 8080
DEFAULT_PORT = 8090
TEMPLATE_DIR = Path(__file__).resolve().parent / "templates"
_thread_local = threading.local()
Binary file not shown.
+1 -1
View File
@@ -26,7 +26,7 @@ ExecStart=$SCRIPT_DIR/start_dashboard.sh
Restart=always
RestartSec=5
Environment=PYTHONUNBUFFERED=1
Environment=PORT=8080
Environment=PORT=8090
[Install]
WantedBy=default.target
+12 -1
View File
@@ -229,7 +229,18 @@ def ensure_compatible_model(
)
except Exception as export_err:
print(f"[engine_utils] ❌ Engine recompilation failed: {export_err}")
print(f"[engine_utils] ⚠️ Falling back to PyTorch .pt model: {pt_model}")
print(f"[engine_utils] ⚠️ Falling back safely to PyTorch .pt model: {pt_model}")
return str(pt_model)
# Post-compilation verification check
is_new_compatible, new_err = verify_engine_compatibility(
new_engine_path,
device=device,
imgsz=imgsz,
)
if not is_new_compatible:
print(f"[engine_utils] ❌ Newly compiled engine '{new_engine_path.name}' failed verification: {new_err}")
print(f"[engine_utils] ⚠️ Fail-safe activated: Falling back to PyTorch .pt model: {pt_model.name}")
return str(pt_model)
# If config file is specified, update it
+17 -1
View File
@@ -32,7 +32,23 @@ class DetectionTracker:
model_path = Path(validated_model_path)
self.model_kind = model_path.suffix.lower().lstrip(".") or "unknown"
self.model = YOLO(validated_model_path, task="detect")
try:
self.model = YOLO(validated_model_path, task="detect")
except Exception as load_exc:
if self.model_kind == "engine":
from chicken_counter.engine_utils import find_matching_pt_model
print(f"[model] ⚠️ Runtime error loading TensorRT engine: {load_exc}")
pt_alt = find_matching_pt_model(model_path)
if pt_alt and pt_alt.exists():
print(f"[model] 🛡️ Fail-safe activated: Falling back to PyTorch .pt model: {pt_alt.name}")
self.model = YOLO(str(pt_alt), task="detect")
self.model_kind = "pt"
model_path = pt_alt
else:
raise
else:
raise
self.tracker_config_path = str(Path(config.tracker.tracker_config_path))
self.verbose = config.performance.verbose
self._infer_count = 0
+1 -1
View File
@@ -14,7 +14,7 @@ else
fi
DB_PATH="${DB_PATH:-$SCRIPT_DIR/db/chicken_counts.db}"
PORT="${PORT:-8080}"
PORT="${PORT:-8090}"
DATE_ARG="${DATE_ARG:-}"
CMD=("$PYTHON" "$SCRIPT_DIR/dashboard.py" --port "$PORT" --db "$DB_PATH")
+14 -7
View File
@@ -23,16 +23,23 @@ cameras=("CC1" "CC2" "CC3" "CC4")
# Maximum parallel video jobs (default: 4)
MAX_JOBS="${MAX_JOBS:-4}"
echo "=== Starting per-video parallel processing with MAX_JOBS=$MAX_JOBS ==="
DATES_PER_BATCH=$(( MAX_JOBS / 4 ))
if [ "$DATES_PER_BATCH" -lt 1 ]; then
DATES_PER_BATCH=1
fi
echo "=== Starting per-video parallel processing with MAX_JOBS=$MAX_JOBS ($DATES_PER_BATCH dates in parallel) ==="
for date in "${dates[@]}"; do
echo "=== Starting batch for date: $date ==="
for cam in "${cameras[@]}"; do
echo "=== Launching $date ($cam) ==="
$PYTHON -m chicken_counter.cli batch --config configs/cycle7_batch_optimized.yaml --date "$date" --camera "$cam" --no-video &
for ((i=0; i<${#dates[@]}; i+=DATES_PER_BATCH)); do
batch_dates=("${dates[@]:i:DATES_PER_BATCH}")
echo "=== Starting batch for dates: ${batch_dates[*]} ==="
for d in "${batch_dates[@]}"; do
for cam in "${cameras[@]}"; do
echo "=== Launching $d ($cam) ==="
$PYTHON -m chicken_counter.cli batch --config configs/cycle7_batch_optimized.yaml --date "$d" --camera "$cam" --no-video &
done
done
wait || true
echo "=== Date $date completed ==="
echo "=== Completed dates: ${batch_dates[*]} ==="
done
echo "=== All video processing jobs completed ==="