# 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)