File size: 3,671 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
# Quick Reference - Import Statements

## New Import Pattern

```python

# Detection modules

from src.detectors import (

    YOLODetector,

    ViolenceDetector,

    WeaponPersonDetector,

    PoseDetection,

    AnomalyDetector,

)



# Or import from src directly

from src import YOLODetector, ViolenceDetector



# Pipeline

from src.pipeline import VideoCapture



# Configuration

from config import (

    MODEL_PATHS,

    get_model_path,

    DETECTION_THRESHOLDS,

    PROCESSING_PARAMS,

    SECRET_KEY,

    DATABASE_URI,

    MAX_CONTENT_LENGTH,

    UPLOAD_FOLDER,

    PROCESSED_FOLDER,

)

```

## Common Usage Examples

### Load a Model

```python

# Old way

model_path = Path(__file__).parent.parent / "ai_models" / "object_detection" / "yolov8n.pt"



# New way

from config import get_model_path

model_path = get_model_path('yolo')

```

### Get Detection Threshold

```python

# Old way

conf_threshold = 0.25  # Magic number



# New way

from config import DETECTION_THRESHOLDS

conf_threshold = DETECTION_THRESHOLDS['yolo']

```

### Create Detector

```python

from src.detectors import YOLODetector

from config import get_model_path



model_path = get_model_path('yolo')

detector = YOLODetector(model_path=str(model_path))

```

### Access Settings

```python

from config import SECRET_KEY, MAX_CONTENT_LENGTH, UPLOAD_FOLDER



print(f"Upload location: {UPLOAD_FOLDER}")

print(f"Max size: {MAX_CONTENT_LENGTH / (1024*1024)} MB")

```

### Check Available Models

```python

from config import get_all_available_models



models = get_all_available_models()

# Output: {'yolo': True, 'violence': False, 'weapon': True, ...}



for model_name, is_available in models.items():

    status = "βœ“" if is_available else "βœ—"

    print(f"{status} {model_name}")

```

## File Organization Reference

```

src/                          Source code

β”œβ”€β”€ detectors/               AI detection modules

β”‚   β”œβ”€β”€ yolo_detector.py

β”‚   β”œβ”€β”€ violence_detector.py

β”‚   β”œβ”€β”€ weapon_detector.py

β”‚   β”œβ”€β”€ pose_detector.py

β”‚   └── anomaly_detector.py

β”œβ”€β”€ pipeline/                Video processing

β”‚   └── video_capture.py

└── utils/                   Utilities



config/                       Configuration

β”œβ”€β”€ settings.py              App settings

└── model_config.py          Model management



models/                       Model weights (organized by type)

β”œβ”€β”€ object_detection/

β”œβ”€β”€ weapon_detection/

β”œβ”€β”€ pose_detection/

└── anomaly_detection/



webapp/                        Flask web app

β”œβ”€β”€ app.py

β”œβ”€β”€ templates/

└── static/



docs/                         Documentation

β”œβ”€β”€ PROJECT_STRUCTURE.md

└── MIGRATION_GUIDE.md

```

## Environment Setup

```bash

# Install dependencies

pip install -r requirements.txt



# Run web app

cd webapp

python app.py



# Or from root

python -c "from src import YOLODetector; print('βœ“ Imports working')"

```

## Troubleshooting

**"ModuleNotFoundError: No module named 'src'"**
- Ensure you're running from project root directory
- Check that src/__init__.py exists

**"ModuleNotFoundError: No module named 'config'"**
- Check that config/__init__.py exists
- Run from project root

**"Model not found"**
```python

from config import get_all_available_models

print(get_all_available_models())  # Check which models are available

```

**Import errors after migration**
- Make sure webapp/app.py imports were updated
- Verify sys.path includes project root
- Check Python version (3.9+ recommended)