Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
66 lines (52 loc) · 2.15 KB
/
Copy pathconfig.py
File metadata and controls
66 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import torch
import yaml
def load_config(config_path="config.yaml"):
"""Loads the configuration from a YAML file."""
with open(config_path, "r") as f:
config = yaml.safe_load(f)
return config
def get_device(device_str):
"""Determines the processing device (CPU or CUDA)."""
if device_str == "cuda" and torch.cuda.is_available():
return torch.device("cuda")
return torch.device("cpu")
# Load the configuration
config = load_config()
# -- Configurable Parameters --
# Telegram
TELEGRAM_TOKEN = config["telegram"]["token"]
TELEGRAM_CHAT_IDS = config["telegram"]["chat_ids"]
# Alerting
ALERT_COOLDOWN = config["alerting"]["cooldown_seconds"]
ALERT_COOLDOWN_THRESHOLD = config["alerting"]["cooldown_threshold_multiplier"]
MIN_ALERT_INTERVAL = config["alerting"]["min_interval_seconds"]
ALERT_SENSITIVITY_THRESHOLD = config["alerting"]["sensitivity_threshold"]
# Camera
CAM_INDEX = config["camera"]["index"]
CAM_WIDTH = config["camera"]["width"]
CAM_HEIGHT = config["camera"]["height"]
# Processing
DEVICE = get_device(config["processing"]["device"])
COCO_CLASSES_PATH = config["processing"]["coco_classes_path"]
EXECUTION_MODE = config["processing"].get("execution_mode", "sequential")
INTER_FRAME_DELAY = float(config["processing"].get("inter_frame_delay", 0.1))
# Models
MODELS_CONFIG = config["models"]
# Dashboard
REMOVE_BACKGROUND = config["dashboard"]["remove_background"]
# Optional: omitted settings preserve the legacy, non-temporal pipeline.
TRACKING_CONFIG = config.get("tracking", {})
# Display magnifiers and retrospective Telegram video clips.
ALERT_MEDIA_CONFIG = config.get("alert_media", {})
# Shared switch for diagnostic logs and model/confidence zoom labels.
DEBUG_MODE = ALERT_MEDIA_CONFIG.get("debug_mode", True)
if not isinstance(DEBUG_MODE, bool):
raise ValueError("alert_media.debug_mode must be boolean")
def debug_print(*values):
if DEBUG_MODE:
import re
message = " ".join(str(value) for value in values)
if TELEGRAM_TOKEN:
message = message.replace(str(TELEGRAM_TOKEN), "<redacted>")
message = re.sub(r"[a-zA-Z]+://\S+", "<url>", message)
print(message, flush=True)