Files
karung-counting-feedmill-se…/AGENTS.md
T
andrew 2d9c66cbb6
ci / smoke (push) Canceled after 0s
feat: unified config.yaml with extensible model presets (A-D data-driven, E/F ready)
- config.yaml canonical for stream/models/counting/batch/output/camera
- models.modes hold engines+class filters only; conf/iou/min_bbox in detection_params
- predict.py derives tracker roles structurally (no per-mode branching)
- dashboard mode switch validates + persists atomically to config.yaml
- .env keeps secrets/deployment only; zones.json geometry; tracker.yaml hyperparams
- batch_mode.json keeps manual/auto batch mode; legacy model_mode ignored w/ warning
- src/detection+tracking gain iou param (default 0.7 = no behavior change)
2026-09-17 11:44:45 +07:00

4.5 KiB

AGENTS.md — karung (sack counter)

Repo: https://git.proit.id/andrew/karung-counting-feedmill-semarang (transferred from ervan/; old remote redirects, but git remote set-url origin to the new URL).

AI video analytics (Jetson) counting feed sacks loaded onto trucks. UI/log strings are Indonesian (karung=sack, truk=truck); YOLO class names are English (sack, box, truck, person). Details: README.md, docs/.

Which pipeline to touch

  • predict.py = production AND dev CLI (runs as karung-counter.service with zero args). Dev flags: --source VID --env .env --config YAML --model X --output-dir D --output-json F --sack-conf C --truck-conf C --box-conf C --box-model P --model-mode M --batch-timeout S --max-frames N --no-dashboard --no-db. Zero flags = systemd behaviour (config.yaml + .env). Model modes are DATA in config.yaml models.modes (engines + class filters only; conf/iou/min_bbox in models.detection_params): A=combined only; B=v4 truck + yolo11n sack+box; C=A + yolo11n box-only (default); D=v4 truck + best sack-only + yolo11n box-only. New modes need no code change. All modes load .engine files (2-3 coexist, ~24 MB peak); never mix load order assumptions — PyTorch .pt must load before TensorRT .engine.
  • src/ = shared library (detection/tracking/counting/batch). python -m src.main still works but prints a deprecation pointer to predict.py.
  • archive/ = retired experiments (predict_new.py, rpo_iki/, simple_predict.py, check/merge/test scripts). Git history preserved via git mv. Don't resurrect without asking.

Gotchas

  • Unified config: config.yaml is canonical (stream/models/counting/batch/ output/camera via src/config_loader.py); .env holds secrets + deployment only (RTSP_URL, dashboard host/ports/secret/site); zones.json holds geometry (polygons + left/right limits — knob keys there are ignored, warned); cfg/tracker.yaml holds tracker hyperparams. src/config.py (v3 keys like LOCAL_RTSP) is deprecated — don't add keys there. Dashboard mode switches write config.yaml models.active_mode (atomic, manual restart to apply); batch_mode.json keeps only manual/auto batch mode.
  • Counting filters by class name, not ID: SackDetector/BoxDetector/ TruckDetector filter via BaseDetector(class_filter) (src/detection.py); tracker keeps ("sack", "truck", "box") (src/tracking.py); counting uses MultiClassLineCounter = dual LineCrossCounters on one shared line (src/counting.py). Same line geometry + 30px dedup for sacks and boxes.
  • All weights live in models/ (.pt/.onnx tracked; .engine gitignored — rebuild via export_model.py; per-mode detector/filter matrix in models/modelREADME.md). Verified classes: truck-detector={truck}, model_karung_truk/v4-best={sack,truck}, karung-dimuat-*-seg-200e= {person,sack} (seg; persons drawn, never counted), best={sack}, yolo11n-…-sack+box={sack,box}. predict.py auto-picks MODEL_PATH env, else models/v4-best.engine > .pt > v4-best (1).pt > models/model_karung_truk.*. src/config.py defaults: models/best.engine (sack) / models/truck-detector.engine.
  • Counting trigger is the bbox top edge (y1) vs a truck-anchored line band (src/counting.py, src/truck_roi.py); truck detect runs every 15th frame only.
  • Tests: python -m pytest tests/ -q (smoke tests for counting, batch, config — pure-Python, no cv2/ultralytics needed). CI (.github/workflows/ci.yml) installs only numpy python-dotenv pytest + runs pytest + compileall. Deps: requirements.txt (unpinned; never pip-install torch from PyPI on the Jetson — use the NVIDIA wheels already on device). For visual checks run on a video file (--source), not the live RTSP.
  • Don't commit state: .gitignore excludes *.engine (rebuildable), *.mp4/*.jpg/*.png, *.db, .env, batch_history_folder/. Videos and local DBs already sit untracked in the working tree — leave them alone.

Deploy (Jetson 192.168.192.96, user jetson)

  • deploy_to_jetson.py syncs predict.py, counter_dashboard.py, templates/{operator,monitoring,base}.html, .env, plus models/*.engine (skips missing local files; creates remote models/). .pt/.onnx stay local. Edits elsewhere (e.g. src/, zones.json) need manual sync.
  • Services: karung-counter (predict.py), karung-counter-dashboard (counter_dashboard.py, ports 5000/5721). TensorRT export: python export_model.py models/<name>.pt — run on the Jetson.