# pedbrgs/fire-detection architecture

> Architecture diagram of the GitHub repository pedbrgs/fire-detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pedbrgs/fire-detection
- Repository: https://github.com/pedbrgs/fire-detection

## Overview

##### Project Type and Purpose
- The repository is a fire detection system that implements hybrid methods for detecting fire and smoke. It uses spatial detection (via YOLO-based networks) as the first stage and a temporal analysis (via techniques such as area variation and temporal persistence) as the second stage. In addition, it provides baseline CNN models for comparison.
- The README clearly explains the two modes of operation (YOLO detection plus temporal analysis and the simpler baseline models) and provides Docker-based deployment instructions.

##### Analyzing the File Structure
- Top-Level Files/Directories:
- Dockerfile, LICENSE, README.md: Help with deployment, documentation, and licensing.
- baseline.py and detect.py: Main entry points for running the baseline and hybrid detection systems.
- “data”: Contains configuration files (YAML) for various datasets, hyperparameter configurations (under data/hyps), and supplementary scripts to download required weights and datasets.
- “models”: Contains definitions and configurations for various detection networks (e.g., YOLOv5, YOLOv4) including subdirectories (hub) for pre-configured architectures.
- “temporal”: Contains the temporal tracker (tracker.py) that implements the temporal analysis stage.
- “utils”: Hosts utility modules for data augmentation, datasets, logging (including integration with services such as wandb), and even an optional REST API interface.
- “scripts”: Contains shell scripts to download models.
- “examples”: Contains sample videos to test the detection system.

##### Main Components and Their Relationships
a. Input & Data Management:
- Video/Image inputs stored in the “examples” folder or provided by the user.
- “data” folder holds dataset configurations and hyperparameter files.

b. Detection Engine (Spatial Analysis):
- This component is implemented in detect.py and uses the "models" directory. It leverages:
- YOLOv5 networks (with multiple model configurations under models/yolov5*.yaml and models/hub/)
- YOLOv4 alternatives (referenced by configuration files such as models/yolov4.cfg).
- Baseline models for fire detection are implemented in baseline.py.

c. Temporal Analysis:
- The second stage is realized via temporal analysis techniques.
- “temporal/tracker.py” and associated flags like “--temporal tracker” in the command line allow you to choose between area variation (AVT) and persistence (TPT) methods.

d. Auxiliary Components:
- “utils”: Contains supporting code for data augmentation, dataset preparation, activation functions, custom losses, and logging.
- Submodules like the Flask REST API in “utils/flask_rest_api” may also serve as an interface for external integration.
- Logging utilities (e.g., wandb integrated logging under utils/loggers) help in monitoring system performance.

e. Deployment:
- The Dockerfile at the root and additional deployment scripts in “utils/google_app_engine” ensure the project can be containerized and deployed in cloud environments.

##### Architectural Patterns and Design Principles
- Separation of concerns – clearly distinct modules for data management, spatial detection, temporal analysis, and utility functions.
- Modularity – different YOLO models and baseline models are maintained separately, facilitating ease of testing and extension.
- Flexibility – command-line options allow the system to switch between different temporal techniques (AVT vs. TPT) and networks.
- Containerization – Docker integration encapsulates the environment setup.

##### Final Advice for the Principal Software Engineer
- Input sources and pre-processing.
- Detection models (with subdivisions if necessary).
- Temporal analysis components.
- Support utilities (e.g., logging, API endpoints).
- To add annotations for architectural decisions such as containerized deployment, modularity, and the integration of external datasets and pretrained weights.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input & Data Management
    subgraph "Input & Data Management"
        DataConfig["Data Configurations (data)"]:::input
        ExampleInputs["Example Inputs (examples)"]:::input
    end

    %% Spatial Detection Module
    subgraph "Spatial Detection Module"
        DetectNode["Spatial Detection: detect.py"]:::detection
        ModelNode["Model Configurations: models"]:::detection
        BaselineDetection["Baseline Detection: baseline.py"]:::detection
        DetectionResults["Detection Results"]:::detection
    end

    %% Temporal Analysis Module
    subgraph "Temporal Analysis Module"
        TemporalTracker["Temporal Tracker (temporal/tracker.py)"]:::temporal
    end

    %% Auxiliary Utilities & Support
    subgraph "Auxiliary Utilities & Support"
        Utilities["Utilities & Support (utils)"]:::utility
    end

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        Docker["Dockerfile"]:::deployment
        DeploymentScripts["Google App Engine (utils/google_app_engine)"]:::deployment
    end

    %% Data flow from Input to Spatial Detection Module
    DataConfig -->|"feeds"| DetectNode
    ExampleInputs -->|"feeds"| DetectNode
    DataConfig -->|"feeds"| BaselineDetection
    ExampleInputs -->|"feeds"| BaselineDetection

    %% Internal flow in Spatial Detection Module
    DetectNode -->|"uses"| ModelNode
    DetectNode -->|"outputs"| DetectionResults
    ModelNode -->|"contributes"| DetectionResults
    BaselineDetection -->|"outputs"| DetectionResults

    %% Flow to Temporal Analysis Module
    DetectionResults -->|"passed_to"| TemporalTracker

    %% Logging & Support interactions
    DetectionResults -->|"logs_to"| Utilities
    TemporalTracker -->|"reports_to"| Utilities

    %% Deployment interactions
    Docker ---|"containerizes"| Utilities
    DeploymentScripts ---|"deploys"| Utilities

    %% Styles
    classDef input fill:#ffccff,stroke:#cc0099,stroke-width:2px;
    classDef detection fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef temporal fill:#ccffcc,stroke:#339933,stroke-width:2px;
    classDef utility fill:#fff0b3,stroke:#cc9900,stroke-width:2px;
    classDef deployment fill:#ffd6cc,stroke:#ff6600,stroke-width:2px;

    %% Click Events
    click DataConfig "https://github.com/pedbrgs/fire-detection/tree/main/data"
    click ExampleInputs "https://github.com/pedbrgs/fire-detection/tree/main/examples"
    click DetectNode "https://github.com/pedbrgs/fire-detection/blob/main/detect.py"
    click ModelNode "https://github.com/pedbrgs/fire-detection/tree/main/models"
    click BaselineDetection "https://github.com/pedbrgs/fire-detection/blob/main/baseline.py"
    click TemporalTracker "https://github.com/pedbrgs/fire-detection/blob/main/temporal/tracker.py"
    click Utilities "https://github.com/pedbrgs/fire-detection/tree/main/utils"
    click Docker "https://github.com/pedbrgs/fire-detection/tree/main/Dockerfile"
    click DeploymentScripts "https://github.com/pedbrgs/fire-detection/tree/main/utils/google_app_engine"
```
