itsluckysharma01's picture
Upload 39 files
cb3c674 verified

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)