File size: 5,775 Bytes
cb3c674 | 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | # Project Structure Guide
## Overview
NETRA is now organized into clear, logical sections for easy maintainability and scalability.
```
NETRA/
βββ src/ Source code
β βββ detectors/ AI detection modules
β βββ pipeline/ Video processing pipeline
β βββ utils/ Utility functions
βββ models/ Trained AI model weights
βββ config/ Configuration files
βββ webapp/ Flask web application
βββ docs/ Documentation
βββ tests/ Unit tests
βββ README.md Main documentation
```
## Directory Details
### `/src` - Source Code
Contains all core application code organized by functionality.
#### `/src/detectors`
All AI detection models wrapped in consistent interfaces:
- **`yolo_detector.py`** - Object detection (people, cars, animals)
- Uses YOLOv8 from Ultralytics
- Model: `models/object_detection/yolov8n.pt`
- **`violence_detector.py`** - Violence/fight detection
- Uses Keras CNN trained on violence data
- Model: `models/violence_detection/violence_model.h5`
- **`weapon_detector.py`** - Gun/knife detection
- Uses custom trained YOLO model
- Models: `models/weapon_detection/best.pt`, `models/object_detection/yolov8n.pt`
- **`pose_detector.py`** - Human pose detection
- Uses YOLOv11 Pose
- Model: `models/pose_detection/yolo11n-pose.pt`
- **`anomaly_detector.py`** - Anomalous behavior detection
- Uses PyTorch anomaly model
- Model: `models/anomaly_detection/best.bin`
#### `/src/pipeline`
Video input and processing modules:
- **`video_capture.py`** - Camera/RTSP stream capture
- Motion detection using MOG2
- ROI extraction for efficient processing
#### `/src/utils`
Helper utilities and common functions (for future expansion)
### `/models` - Trained Model Weights
Organized by detection type:
```
models/
βββ object_detection/ YOLO object models
βββ violence_detection/ Violence detection models
βββ weapon_detection/ Weapon detection models
βββ pose_detection/ Pose detection models
βββ anomaly_detection/ Anomaly detection models
```
Each folder contains the trained weights ready for inference.
### `/config` - Configuration Files
Centralized configuration management:
- **`settings.py`** - Application-wide settings
- Flask configuration
- Database settings
- File upload parameters
- Session management
- **`model_config.py`** - Model-specific configuration
- All model paths (easy updates)
- Detection thresholds
- Processing parameters
### `/webapp` - Flask Web Application
The complete web interface:
```
webapp/
βββ app.py Main Flask application
βββ templates/ HTML templates
βββ static/ CSS, JavaScript, images
βββ uploads/ User uploaded videos
βββ processed/ Processed video outputs
βββ instance/ SQLite database
```
### `/docs` - Documentation
- **`ARCHITECTURE.md`** - System architecture overview
- **`ANOMALY_DETECTION_GUIDE.md`** - Anomaly detection setup
- **`SETUP.md`** - Installation and setup instructions
- **`API.md`** - API reference
### `/tests` - Unit Tests
Test files for core modules (optional for future):
- `test_detectors.py` - Tests for detector modules
- `test_pipeline.py` - Tests for video pipeline
## Import Examples
### Old Structure (Before)
```python
from NETRA.violence_detector import ViolenceDetector
from NETRA.yolo_detector import YOLODetector
from pose_detection import PoseDetection
```
### New Structure (After)
```python
from src.detectors import ViolenceDetector, YOLODetector, PoseDetection
from src.pipeline import VideoCapture
from config import MODEL_PATHS, DETECTION_THRESHOLDS
```
## File Organization Benefits
β
**Clear Separation** - Code organized by functionality
β
**Easy Navigation** - Developers know where to find things
β
**Scalability** - Easy to add new detectors or features
β
**Maintainability** - Configuration centralized
β
**Model Management** - All models in one organized place
β
**Documentation** - All docs in dedicated folder
## Configuration Usage
### Accessing Model Paths
```python
from config import MODEL_PATHS, get_model_path
# Get specific model path
violence_model = get_model_path('violence')
# Get all available models
from config import get_all_available_models
models = get_all_available_models()
# Output: {'violence': True, 'yolo': True, 'weapon': True, ...}
```
### Accessing Thresholds
```python
from config import DETECTION_THRESHOLDS
yolo_threshold = DETECTION_THRESHOLDS['yolo'] # 0.25
violence_threshold = DETECTION_THRESHOLDS['violence'] # 0.6
```
### Accessing Settings
```python
from config import SECRET_KEY, MAX_CONTENT_LENGTH, UPLOAD_FOLDER
print(f"Max upload: {MAX_CONTENT_LENGTH}")
print(f"Upload location: {UPLOAD_FOLDER}")
```
## Next Steps
1. β
New folder structure created
2. β
Files reorganized
3. β
Configuration centralized
4. π Update imports in `webapp/app.py`
5. π Test all functionality
## Troubleshooting
**"Module not found" errors:**
- Ensure sys.path includes project root
- Check that `__init__.py` files exist in all packages
**Model not loading:**
- Check `config/model_config.py` paths
- Verify model files exist in `models/` directory
- Check file permissions
**Import issues:**
- Run from project root directory
- Ensure Python path includes `src/`
|