itsluckysharma01 commited on
Commit
80cfb2b
·
verified ·
1 Parent(s): 7a674bb

Upload 6 files

Browse files
config/__init__.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ """
2
+ Configuration Module
3
+ Centralized settings and model configuration
4
+ """
5
+
6
+ from .settings import *
7
+ from .model_config import *
config/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (383 Bytes). View file
 
config/__pycache__/model_config.cpython-310.pyc ADDED
Binary file (2.67 kB). View file
 
config/__pycache__/settings.cpython-310.pyc ADDED
Binary file (1.12 kB). View file
 
config/model_config.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Model Configuration
3
+ Centralizes all model paths and loading configurations
4
+ """
5
+
6
+ from pathlib import Path
7
+
8
+ # Project root
9
+ PROJECT_ROOT = Path(__file__).parent.parent
10
+
11
+ # Model directory (consolidated to ai_models/)
12
+ MODELS_DIR = PROJECT_ROOT / "ai_models"
13
+
14
+ # Model paths - Organized by detection type
15
+ MODEL_PATHS = {
16
+ 'violence': {
17
+ 'model': MODELS_DIR / "violence_detection" / "violence_model.h5",
18
+ 'labels': MODELS_DIR / "violence_detection" / "lb.pickle",
19
+ 'description': 'Violence Detection Model'
20
+ },
21
+ 'yolo': {
22
+ 'candidates': [
23
+ MODELS_DIR / "object_detection" / "yolov8n.pt",
24
+ MODELS_DIR / "object_detection" / "yolov8s.pt",
25
+ ],
26
+ 'description': 'YOLO Object Detection Model'
27
+ },
28
+ 'weapon': {
29
+ 'gun_model_candidates': [
30
+ MODELS_DIR / "weapon_detection" / "GunDetector.pt",
31
+ MODELS_DIR / "weapon_detection" / "best.pt",
32
+ ],
33
+ 'person_model_candidates': [
34
+ MODELS_DIR / "object_detection" / "yolov8n.pt",
35
+ MODELS_DIR / "object_detection" / "yolov8s.pt",
36
+ ],
37
+ 'description': 'Weapon & Person Detection Model'
38
+ },
39
+ 'pose': {
40
+ 'candidates': [
41
+ MODELS_DIR / "pose_detection" / "yolo11n-pose.pt",
42
+ ],
43
+ 'description': 'Pose Detection Model'
44
+ },
45
+ 'anomaly': {
46
+ 'candidates': [
47
+ MODELS_DIR / "anomaly_detection" / "best.bin",
48
+ ],
49
+ 'description': 'Anomaly Detection Model'
50
+ },
51
+ 'analysis': {
52
+ 'candidates': [
53
+ MODELS_DIR / "analysis_models" / "fight_detection_model.h5",
54
+ MODELS_DIR / "analysis_models" / "CustomCNN150.h5",
55
+ MODELS_DIR / "analysis_models" / "CustomCNN100.h5",
56
+ MODELS_DIR / "analysis_models" / "CustomCNN.h5",
57
+ ],
58
+ 'description': 'Advanced Analysis Model (Fight/Behavior Detection)'
59
+ }
60
+ }
61
+
62
+ # Detection thresholds
63
+ DETECTION_THRESHOLDS = {
64
+ 'yolo': 0.25,
65
+ 'violence': 0.6,
66
+ 'weapon': 0.5,
67
+ 'anomaly': 0.5,
68
+ }
69
+
70
+ # Processing parameters
71
+ PROCESSING_PARAMS = {
72
+ 'frame_skip': 10, # Process every 10th frame in video analysis
73
+ 'alert_threshold': 3, # Consecutive frames before alert
74
+ 'max_upload_size': 500 * 1024 * 1024, # 500MB
75
+ }
76
+
77
+
78
+ def get_model_path(model_name: str, model_type: str = None):
79
+ """
80
+ Get model path by name
81
+
82
+ Args:
83
+ model_name: 'violence', 'yolo', 'weapon', 'pose', 'anomaly'
84
+ model_type: specific model variant (if applicable) - for weapon, use 'gun' or 'person'
85
+
86
+ Returns:
87
+ Path to model file or None if not found
88
+ """
89
+ if model_name not in MODEL_PATHS:
90
+ return None
91
+
92
+ config = MODEL_PATHS[model_name]
93
+
94
+ # Handle single model file case
95
+ if 'model' in config:
96
+ return config['model'] if config['model'].exists() else None
97
+
98
+ # Handle weapon model special case with gun and person models
99
+ if model_name == 'weapon':
100
+ if model_type == 'gun' and 'gun_model_candidates' in config:
101
+ for candidate in config['gun_model_candidates']:
102
+ if candidate.exists():
103
+ return candidate
104
+ elif model_type == 'person' and 'person_model_candidates' in config:
105
+ for candidate in config['person_model_candidates']:
106
+ if candidate.exists():
107
+ return candidate
108
+ elif not model_type:
109
+ # Return gun model by default for weapon
110
+ for candidate in config.get('gun_model_candidates', []):
111
+ if candidate.exists():
112
+ return candidate
113
+ return None
114
+
115
+ # Handle standard candidates case
116
+ if 'candidates' in config:
117
+ for candidate in config['candidates']:
118
+ if candidate.exists():
119
+ return candidate
120
+
121
+ return None
122
+
123
+
124
+ def get_all_available_models():
125
+ """
126
+ Get list of all available models
127
+
128
+ Returns:
129
+ dict: {model_name: is_available}
130
+ """
131
+ available = {}
132
+ for model_name in MODEL_PATHS.keys():
133
+ path = get_model_path(model_name)
134
+ available[model_name] = path is not None
135
+
136
+ return available
config/settings.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Settings Configuration
3
+ Application-wide settings and configuration
4
+ """
5
+
6
+ from pathlib import Path
7
+
8
+ # Flask Settings
9
+ FLASK_ENV = 'development'
10
+ DEBUG = True
11
+ SECRET_KEY = 'netra-surveillance-secret-key-2024'
12
+
13
+ # Paths
14
+ PROJECT_ROOT = Path(__file__).parent.parent
15
+ INSTANCE_FOLDER = PROJECT_ROOT / 'instance'
16
+ UPLOAD_FOLDER = PROJECT_ROOT / 'webapp' / 'uploads'
17
+ PROCESSED_FOLDER = UPLOAD_FOLDER / 'processed'
18
+
19
+ # Ensure all folders exist
20
+ INSTANCE_FOLDER.mkdir(parents=True, exist_ok=True)
21
+ UPLOAD_FOLDER.mkdir(parents=True, exist_ok=True)
22
+ PROCESSED_FOLDER.mkdir(parents=True, exist_ok=True)
23
+
24
+ # Database - use absolute path, properly formatted for SQLite on Windows
25
+ DB_FILE = INSTANCE_FOLDER / 'netra.db'
26
+ # Convert absolute path to URL format (3 slashes + drive letter + rest of path)
27
+ DB_URL = str(DB_FILE).replace('\\', '/')
28
+ DATABASE_URI = f'sqlite:///{DB_URL}'
29
+ SQLALCHEMY_TRACK_MODIFICATIONS = False
30
+
31
+ # File Upload
32
+ MAX_CONTENT_LENGTH = 500 * 1024 * 1024 # 500MB
33
+
34
+ # Video Processing
35
+ VIDEO_CODEC = 'mp4v'
36
+ VIDEO_FPS = 20.0
37
+
38
+ # Logging
39
+ LOG_LEVEL = 'INFO'
40
+ LOG_FILE = Path(__file__).parent.parent / 'netra.log'
41
+
42
+ # CORS Settings
43
+ CORS_ENABLED = False
44
+
45
+ # Session
46
+ PERMANENT_SESSION_LIFETIME = 3600 # 1 hour
47
+
48
+ # Model Loading
49
+ AUTO_LOAD_MODELS = True
50
+ GRACEFUL_MODEL_FALLBACK = True