An AI-powered system for detecting wildfires in images and video streams using deep learning.
This system uses computer vision and deep learning to detect the presence of wildfires in images and video streams. The project is implemented in three phases:
- Phase 1: Core AI/ML model for image-based fire detection
- Phase 2: Real-time webcam integration
- Phase 3: Raspberry Pi deployment
- Phase 4: Web Interface Integration
- Transfer learning using MobileNetV2 for efficient fire detection
- Real-time webcam monitoring with visual alerts
- Comprehensive data visualization and model performance analysis
- Interactive dataset verification and cleaning tools
- Automated model evaluation and reporting
- Clone this repository:
git clone [repository-url]
cd firedetect- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtfiredetect/
├── data/
│ ├── fire/ # Fire images for training
│ ├── no_fire/ # Non-fire images for training
│ └── review/ # Images requiring manual review
├── src/
│ ├── data.py # Data loading and preprocessing
│ ├── model.py # Neural network model definition
│ ├── train.py # Training script
│ ├── inference.py # Inference module
│ └── visualize.py # Visualization tools
├── models/ # Saved model files
├── logs/ # Training and inference logs
├── visualizations/ # Generated plots and visualizations
├── requirements.txt
└── README.md
web_interface/
├── app.py # Web application for camera streaming and detection
├── static/ # Static files for web interface
└── templates/ # HTML templates for web interface
-
Data Module (
data.py):- Handles dataset loading and preprocessing
- Implements data augmentation for training
- Manages training/validation data splits
-
Model Module (
model.py):- Defines the MobileNetV2-based neural network architecture
- Configures transfer learning layers
- Sets up model compilation with appropriate loss and metrics
-
Training Pipeline (
train.py):- Orchestrates the training process
- Implements early stopping and model checkpointing
- Saves trained models to disk
-
Visualization Module (
visualize.py):- Generates performance visualizations
- Creates confusion matrices and evaluation reports
- Produces dataset distribution plots
-
Inference Module (
inference.py):- Loads trained models
- Performs prediction on new images
- Processes results for interpretation
-
Web Interface (
app.py):- Provides browser-based UI for the system
- Handles camera feed integration
- Displays real-time detection results
- Training data flows from the Data Module to the Training Pipeline
- The Model Module provides the architecture used by the Training Pipeline
- The Training Pipeline generates artifacts for the Visualization Module
- The Inference Module uses the trained model for predictions
- The Web Interface uses the Inference Module for real-time detection on camera feeds
For proper training, organize your dataset:
- Place fire images in
data/fire/ - Place non-fire images in
data/no_fire/
Ensure your dataset is properly categorized and labeled before proceeding with training.
python src/train.py --data_dir data/ --epochs 50 --batch_size 32The training process includes:
- Automatic data augmentation
- Transfer learning with MobileNetV2
- Early stopping to prevent overfitting
- Model checkpointing to save the best model
- Comprehensive visualization generation
During training, the system automatically generates:
- Dataset distribution plots
- Sample image grids
- Training/validation metrics plots
- Confusion matrices
- Detailed evaluation reports
All visualizations are saved in the visualizations/ directory.
python src/inference.py --model_path models/best_model.h5 --image_path path/to/image.jpgTo use the web interface for real-time wildfire detection:
cd web_interface
python app.pyThis will start a web server that provides:
- Real-time camera streaming
- Fire detection on camera feed
- Visual alerts when fire is detected
The system uses a transfer learning approach based on MobileNetV2:
- Pre-trained on ImageNet
- Fine-tuned for wildfire detection
- Additional custom layers for binary classification
- Optimized for real-time performance
The model is evaluated on:
- Accuracy
- Precision
- Recall
- F1-score
- Confusion matrix
- Place fire images in
data/fire/ - Place non-fire (normal forest) images in
data/no_fire/ - Supported formats: JPG, PNG
- Recommended minimum dataset size: 1000 images per class
- Added comprehensive data visualization tools
- Implemented interactive dataset verification system
- Enhanced model evaluation with detailed metrics
- Added automatic visualization generation during training
- Improved documentation and code organization