munals commited on
Commit
c562df1
Β·
verified Β·
1 Parent(s): b274069

Update backend/config.py

Browse files
Files changed (1) hide show
  1. backend/config.py +32 -45
backend/config.py CHANGED
@@ -1,20 +1,14 @@
1
- """
2
- HaramGuard β€” Central Configuration
3
- =====================================
4
- Edit this file to tune thresholds without touching agent code.
5
- """
6
-
7
- import os
8
-
9
- # ── API Keys ─────────────────────────────────────────────────────────
10
- GROQ_API_KEY = os.getenv('GROQ_API_KEY', 'Secret')
11
- ANTHROPIC_KEY = os.getenv('ANTHROPIC_KEY', 'YOUR_ANTHROPIC_KEY_HERE')
12
 
13
  # ── Paths ─────────────────────────────────────────────────────────────
14
- VIDEO_PATH = 'hajj_real_video.mp4'
15
  DB_PATH = 'outputs/hajjflow_rt.db'
16
  MODEL_PATH = 'yolo11l.pt' # swap to 'yolov8x.pt' for better detection
17
 
 
 
 
 
 
18
  # ── PerceptionAgent ───────────────────────────────────────────────────
19
  PERCEPTION_MAX_PERSONS = 500
20
  PERCEPTION_MAX_DENSITY = 50.0
@@ -23,45 +17,38 @@ PERCEPTION_IOU = 0.5
23
  PERCEPTION_IMGSZ = 1024
24
 
25
  # ── RiskAgent ─────────────────────────────────────────────────────────
26
- # Single-camera partial-view calibration:
27
- # Camera sees near crowd first, far crowd later β†’ peak across window is
28
- # more representative than instantaneous count.
29
- # Metric: EMA of per-frame peak (sliding-peak + exponential smoothing).
30
  #
31
- # Observed range from 17-frame demo: ~7–70 persons
32
- # Thresholds chosen so the demo naturally traverses LOW→MEDIUM→HIGH:
33
- # LOW : peak_ema < 20 (sparse, camera sees near edge only)
34
- # MEDIUM : 20–49 (moderate, mid-crowd visible)
35
- # HIGH : β‰₯ 50 (dense, full crowd fills frame)
36
-
37
- RISK_WINDOW_SIZE = 17 # match demo frame count β€” window = one full demo loop
38
- RISK_HIGH_THRESHOLD = 0.65 # score >= 0.65 β†’ HIGH (β‰ˆ peak_ema β‰₯ 50 persons)
39
- RISK_MED_THRESHOLD = 0.35 # score >= 0.35 β†’ MEDIUM (β‰ˆ peak_ema β‰₯ 20 persons)
40
- RISK_HIGH_DENSITY = 1.0 # kept for compression calc
41
- RISK_HIGH_COUNT = 50 # normalizer: peak_ema / HIGH_COUNT β†’ score 0–1
42
- RISK_EMA_ALPHA = 0.6 # raised from 0.4 β€” faster reaction to crowd changes
43
-
44
- # Fruin LoS-calibrated weights (Fruin 1971 + UQU Haram research)
45
- # W_DENSITY raised 0.50β†’0.60: fixes structural ceiling bug where HIGH was unreachable
46
- # Old weights (0.65/0.15/0.10/0.07/0.03) used by RiskAgent directly β€” now agent owns them
47
- RISK_W_DENSITY = 0.60 # Fruin count-based primary (c_score=1.0 β†’ 0.60 > HIGH_THRESHOLD)
48
- RISK_W_SPACING = 0.10 # physical spacing between persons
49
- RISK_W_TREND = 0.10 # rising/stable/falling (ROC handled inside agent)
50
- RISK_W_COMPRESSION = 0.10 # crowd compression
51
- RISK_W_FLOW = 0.00 # flow velocity (disabled β€” noisy without optical flow)
52
- RISK_W_DISTRIBUTION = 0.00 # spatial distribution (replaced by grid-based Path 4)
53
- RISK_SPACING_REF = 120.0 # px β€” comfortable spacing
54
 
55
  # ── ReflectionAgent ───────────────────────────────────────────────────
56
  REFLECTION_BIAS_WINDOW = 10 # reduced: 17-frame loop, catch bias faster
57
- REFLECTION_CROWD_LOW_THRESH = 15 # chronic LOW suspicious above 15 persons
58
- REFLECTION_HIGH_CROWD_THRESH = 50 # 50+ persons but LOW β†’ upgrade to MEDIUM
59
- REFLECTION_OVER_EST_THRESH = 15 # HIGH risk but <15 persons β†’ downgrade
60
 
61
  # ── OperationsAgent ───────────────────────────────────────────────────
62
- OPS_RATE_LIMIT_SEC = 60 # reduced: 1 min cooldown (pipeline is slow, 5min was too long)
63
- OPS_P0_SCORE = 0.65 # aligned with RISK_HIGH_THRESHOLD
64
- OPS_P1_SCORE = 0.35 # aligned with RISK_MED_THRESHOLD
65
 
66
  # ── API Server ─────────────────────────────────────────────────────────
67
  API_PORT = 8000
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  # ── Paths ─────────────────────────────────────────────────────────────
3
+ VIDEO_PATH = 'hajj_multi_video_annotated.mp4'
4
  DB_PATH = 'outputs/hajjflow_rt.db'
5
  MODEL_PATH = 'yolo11l.pt' # swap to 'yolov8x.pt' for better detection
6
 
7
+ # ── Cached Detection Mode ────────────────────────────────────────────
8
+ # When set, PerceptionAgent reads pre-computed detections from JSON
9
+ # instead of running YOLO live. Set to None to use live YOLO.
10
+ CACHED_DETECTIONS_PATH = 'cached_hajj_multi_video_detections.json'
11
+
12
  # ── PerceptionAgent ───────────────────────────────────────────────────
13
  PERCEPTION_MAX_PERSONS = 500
14
  PERCEPTION_MAX_DENSITY = 50.0
 
17
  PERCEPTION_IMGSZ = 1024
18
 
19
  # ── RiskAgent ─────────────────────────────────────────────────────────
20
+ # Risk is based on Fruin density computed from a K-window aggregate
21
+ # of unique track IDs per clip segment.
 
 
22
  #
23
+ # Risk levels (density_pct):
24
+ # HIGH : density_pct > 80
25
+ # MEDIUM : density_pct > 20
26
+ # LOW : density_pct <= 20
27
+ #
28
+ RISK_WINDOW_SIZE = 30
29
+ RISK_HIGH_THRESHOLD = 150 # legacy β€” kept for reference
30
+ RISK_MED_THRESHOLD = 30 # legacy β€” kept for reference
31
+ RISK_HIGH_DENSITY = 1.0
32
+ RISK_HIGH_COUNT = 100
33
+ RISK_EMA_ALPHA = 0.6
34
+
35
+ # ── Clip segmentation ──────────────────────────────────────────────
36
+ CLIP_JUMP_THRESHOLD = 30 # legacy β€” kept for reference
37
+ CLIP_P_JUMP = 40 # person count jump >= 40 β†’ boundary candidate
38
+ CLIP_D_JUMP = 0.4 # density_score jump >= 0.4 β†’ boundary candidate
39
+ CLIP_MIN_LEN = 10 # boundary must persist >= 10 frames (glitch filter)
40
+ CLIP_K_WINDOW = 17 # aggregate window: union of unique IDs over K frames
 
 
 
 
 
41
 
42
  # ── ReflectionAgent ───────────────────────────────────────────────────
43
  REFLECTION_BIAS_WINDOW = 10 # reduced: 17-frame loop, catch bias faster
44
+ REFLECTION_CROWD_LOW_THRESH = 40 # chronic LOW suspicious above 40 persons
45
+ REFLECTION_HIGH_CROWD_THRESH = 100 # 100+ persons but LOW β†’ upgrade to MEDIUM
46
+ REFLECTION_OVER_EST_THRESH = 10 # HIGH risk but <10 persons β†’ downgrade
47
 
48
  # ── OperationsAgent ───────────────────────────────────────────────────
49
+ OPS_RATE_LIMIT_SEC = 3 # minimal cooldown: LLM fires immediately on level change
50
+ OPS_P0_SCORE = 0.80 # density_pct > 80% β†’ P0 (HIGH)
51
+ OPS_P1_SCORE = 0.20 # density_pct > 20% β†’ P1 (MEDIUM)
52
 
53
  # ── API Server ─────────────────────────────────────────────────────────
54
  API_PORT = 8000