Quick Reference - Import Statements
New Import Pattern
# 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
# 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
# Old way
conf_threshold = 0.25 # Magic number
# New way
from config import DETECTION_THRESHOLDS
conf_threshold = DETECTION_THRESHOLDS['yolo']
Create Detector
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
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
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
# 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"
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)