A PyTorch-based fire detection system using ResNet50 for binary classification. This repository compares the performance of models trained with and without Unity-generated synthetic fire images.
This project implements a deep learning approach to fire detection using a pre-trained ResNet50 model fine-tuned for binary classification (fire/no-fire). The repository includes two comparative approaches:
- Standard Training: Using only real-world fire and no-fire images
- Unity-Enhanced Training: Incorporating Unity-generated synthetic fire images to augment the dataset
unity_augmentation/
├── sen2fire/ # Scene-based fire dataset
│ ├── scene1/
│ │ ├── fire/
│ │ └── no_fire/
│ └── scene2/
│ ├── fire/
│ └── no_fire/
├── unity_generated/ # Unity synthetic fire images
│ ├── area_1_1.png
│ ├── area_1_2.png
│ └── ...
├── .gitattributes # Git LFS configuration
├── README.md # This file
├── environment.yml # Conda environment file
├── best_fire_model_no_unity.pth # Best model without Unity images
├── best_fire_model_with_unity.pth # Best model with Unity images
├── resnet_with_no_unity.ipynb # Training notebook without Unity images
└── resnet_with_unity.ipynb # Training notebook with Unity images
The model expects your dataset to be organized as follows:
sen2fire/
├── scene1/
│ ├── fire/ # Fire images from scene 1
│ └── no_fire/ # No-fire images from scene 1
├── scene2/
│ ├── fire/ # Fire images from scene 2
│ └── no_fire/ # No-fire images from scene 2
└── ...
† Sen2Fire Dataset: This work uses the Sen2Fire dataset available at https://zenodo.org/records/10881058, originally provided by Rodríguez, Yan, and others. The dataset is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0), which permits use, sharing, and adaptation with appropriate credit.
unity_generated/
├── fire_001.jpg # Synthetic fire images
├── fire_002.jpg
└── ...
- Python 3.8+
- CUDA-compatible GPU (recommended)
- Conda or Miniconda
-
Clone the repository
git clone https://github.com/dastanNurbek/unity_augmentation.git cd unity_augmentation -
Create and activate the conda environment
conda env create -f environment.yml conda activate fire-detection
-
Verify installation
python -c "import torch; print(f'PyTorch version: {torch.__version__}')" python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')"
Use the resnet_with_no_unity.ipynb notebook for training with only real-world images.
-
Open the notebook
jupyter notebook resnet_with_no_unity.ipynb
-
Update dataset paths in the notebook:
BASE_PATH = "./sen2fire" # Path to your scene folders UNITY_IMAGES_PATH = None # Disabled for standard training
-
Configure training parameters:
BATCH_SIZE = 32 NUM_EPOCHS = 50 max_fire_per_scene = 100 # Limit fire images per scene target_fire_ratio = 0.4 # Target 40% fire images
-
Run all cells to train and evaluate the model
Use the resnet_with_unity.ipynb notebook for training with Unity-generated synthetic images.
-
Open the notebook
jupyter notebook resnet_with_unity.ipynb
-
Update dataset paths in the notebook:
BASE_PATH = "./sen2fire" UNITY_IMAGES_PATH = "./unity_generated" # Path to Unity images
-
Configure Unity integration:
use_all_unity = True # Use all Unity images target_fire_ratio = 0.5 # Higher ratio with synthetic data
-
Run all cells to train and evaluate the model
- Scene-based sampling: Limits fire images per scene to prevent overfitting
- Target ratio control: Maintains desired fire/no-fire ratio
- Unity integration: Seamlessly incorporates synthetic fire images
- Weighted sampling: Handles class imbalance automatically
- Data augmentation: Random flips, rotations, and color jittering
- Early stopping: Prevents overfitting with patience-based stopping
- Learning rate scheduling: Reduces learning rate on plateau
- Classification reports: Precision, recall, and F1-scores
- Confusion matrices: Visual performance analysis
- Training curves: Loss and accuracy plots
- Model comparison: Side-by-side performance metrics
- Base Model: ResNet50 pre-trained on ImageNet
- Modification: Final fully connected layer replaced for binary classification
- Input Size: 224×224 RGB images
- Output: 2 classes (fire/no-fire)
| Parameter | Value | Description |
|---|---|---|
| Batch Size | 32 | Training batch size |
| Learning Rate | 0.0001 | Adam optimizer learning rate |
| Weight Decay | 1e-4 | L2 regularization |
| Early Stopping | 15 epochs | Patience for early stopping |
| LR Scheduler | ReduceLROnPlateau | Learning rate reduction strategy |
After training, you'll get:
best_fire_model_no_unity.pth: Best performing model without Unity imagesbest_fire_model_with_unity.pth: Best performing model with Unity images- Training history plots (loss and accuracy curves)
- Classification report with precision, recall, and F1-scores
- Confusion matrix visualization
- Model performance comparison between standard and Unity-enhanced approaches
The notebooks will generate comparative results showing:
- Accuracy improvements with synthetic data augmentation
- Precision/Recall trade-offs between approaches
- Training stability and convergence patterns
- Generalization performance on test data
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
dastan.nurbekuly@stud.plus.ac.at
For detailed implementation and theoretical background, refer to the notebooks and code comments.