itsluckysharma01's picture
Clean deployment
4ed7d03

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)

from NETRA.violence_detector import ViolenceDetector
from NETRA.yolo_detector import YOLODetector
from pose_detection import PoseDetection

New Structure (After)

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

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

from config import DETECTION_THRESHOLDS

yolo_threshold = DETECTION_THRESHOLDS['yolo']  # 0.25
violence_threshold = DETECTION_THRESHOLDS['violence']  # 0.6

Accessing Settings

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/