← Back to list

Wildfire Detection with YOLOv8

1)Introduction

Melih Aydin · 2025-05-20 18:18 · 1 claps · 9.0 min read
#wildfire-detection #yolov8 #mathematics
Open on Medium ↗
Wiki topics: 📐 · Mathematics

Wildfire Detection with YOLOv8

1)Introduction

It is a well-known fact that ,forest fires are a very serious environmental threat that causes great damage to forests, wildlife and human property. Due to this great impact, early detection of fires is critical for firefighters to respond quickly and to minimize damage. Traditional and old detection methods (such as watchtowers or satellite imaging) can sometimes be slow or prone to human error. This is exact place that where computer vision comes into play: It can automatically detect smoke or fire in images or videos and send a faster warning to the authorities, thus speeding up communication.

In this project, a simple forest fire detection system demo was developed using the object detection model called YOLOv8. The aim is to train YOLOv8 to recognize smoke and fire in images, thus turning it into an early warning system for forest fires. In this process, transfer learning method was used on a pre-trained YOLOv8 model and the model was fine-tuned in two stages to be able to detect smoke and fire at a simple level.

In the following sections, the dataset used in the project, how the training environment was established and its content, the general training process, the evaluation of the model and finally how the model was deployed via a simple Gradio web application are examined in detail.

1.1)Dataset Overview

Our model is trained on the “Smoke-Fire-Detection-YOLO” dataset from Kaggle. This dataset contains thousands of images labeled with bounding boxes with two classes which are smoke and fire. Also the dataset seperated into three subsets:

Training set: 14,122 images (used for model training )

Validation set: 3,099 images (used for tuning hyperparameters and avoid overfitting)

Test set: 4,306 images (held-out images for evaluating final model performance)

Within these 3 subsets, there is an images/ folder containing the image files and a corresponding labels/ folder containing text files (YOLO format) for the bounding boxes of each image.

The class labels can be simply defined as 0: smoke and 1: fire (as defined in the data.yaml file of the dataset). The dataset is large enough, containing over 21,000 images in total. Smoke and fire examples appear in a wide variety of scenes and locations (forest fires, industrial smoke, small flame events, etc.), giving the model plenty of examples to learn from. The classes are sufficiently balanced, with both smoke and fire well represented in the training data (each class has thousands of labeled examples and is close to each other in total). This allows the model to learn to detect both types of wildfire indicators without being biased towards one class. Having separate training/evaluation/testing sections allows us to train on one set of images, tune and validate the model on another set of images, and finally observe unbiased performance measurements on a test dataset that has never been seen before.

1.2)Setting Environment

Python environment has been created with the essential deep learning frameworks and libraries to train YOLOv8 effectively and smoothly:

Python 3.10 (using the Conda environment for easy package management) PyTorch (with CUDA for GPU acceleration) — Torch 2.0 used with CUDA 11.8 Ultralytics YOLOv8 library (provides easy-to-use functionality to train and run YOLOv8 model) OpenCV and Matplotlib/Seaborn (for image processing and plotting, for visualization) Gradio (for creating simple web interface)

Managed the dependencies with the requirements.txt file. Key packages included with the versions that installed.

(Ultralytics 8.3.137 /Python-3.10.16/ torch-2.7.0+cu118 /gradio 3.23.0 these should be downloaded according to compatibility with python and cuda version)

After creating the conda environment (for example: conda create -n wildfire-yolo python=3.10), the necessary Python packages were installed using pip. PyTorch’s GPU detection capability was tested using the torch.cuda.is_available() command to verify that the training process would be hardware accelerated. The YOLOv8 package was included in the training scripts or Jupyter notebooks with the from ultralytics import YOLO statement.

Also , the Gradio interface to be used for the distribution of the model was also installed, and a basic application file app.py was prepared for use in the later stages.

2)Training the Model

We used the efficient transfer learning approach to train YOLOv8 on our dataset for fire and smoke detection. First, we started with the pre-trained YOLOv8-nano ( yolov8n.pt) model weights provided by Ultralytics and then fine-tuned it on our smoke/fire data. The training was done in two stages in total, inspired by the fastai fine-tuning approach that first trains the head and then fine-tunes all layers:

Head Only Training (Freeze Spine) — first train only the new detection head while freezing the backbone.

Full Fine-Tuning (Unfreeze Spine) — then, unfreeze all layers and continue training to fine-tune the entire model.

This two-stage fine-tuning system allowed the model to quickly learn specific smoke and fire features on the new head without touching the pre-trained backbone features, and then adapt the lower layers for better performance.The bad situation in training is that ,Training all layers at full speed from the beginning can sometimes cause the model to “forget” previously trained features ,known as catastrophic forgetting.So that the stepwise approach used to mitigate this.

2.1)Stage 1 Head Only Training with Frozen Backbone

In the first stage, the “backbone” of the model was frozen and only the sensing head was trained for 15 epochs. This ensured that the previously learned convolutional layers were not updated. Our goal was to quickly adapt the model to new classes such as smoke and fire. The YOLOv8-nano model was used as training parameters and training was performed for 15 epochs. The image size was set to 640x640 and the batch size was 16 images. The first 10 layers were frozen and training was performed with the Stochastic Gradient Descent optimizer with momentum. The learning rate was initially 0.001. The weights of the head were updated throughout the training and by epoch 15 the verification reached r around mAP@0.5. The results were quite satisfactory; precision was measured as about 0.72 and recall as 0.65.

2.2)Stage 2 Full Fine-Tuning with Unfrozeen Model

After the head was trained, the backbone part of the model unfrozed o and trained for another 25 epochs to adjust the weights. In the second phase, the model adjusted the frozen backbone layers to better fit the smoke and fire patterns. The training parameters for the second phase included 25 additional epochs, with a total of 40 epochs. The learning rate was low at the beginning, increased over time, and decreased in the final epoch. All layers were made trainable, and other hyperparameters were kept with the YOLOv8 defaults. During the fine-tuning phase, the model learned more detailed features.By doing so ,at the end of training, the validation metrics increased to Precision ~0.73, Recall ~0.68, and mAP values ​​~0.74 and ~0.43. The losses decreased during training, indicating that there was no overfitting.

3)Mathematical explanations (for better idea)

Loss functions and metrics are explained to better understand the training and evaluation of the model. YOLOv8 calculates multiple loss components during training. Box regression loss measures the error between the predicted box coordinates and the real box. This is done using IoU-based losses;(Intersection over Union)

this loss increases if the predicted box does not overlap with the real object. The box regression loss can be calculated by formula:

Class confidence loss measures the error of the predicted probabilities with respect to the real classes; in the case of two classes, the model should give a high probability if the real object is present and almost zero if it is not. This component is usually calculated using variations of Binary Cross Entropy loss or Focal Loss.

DFL loss is a loss developed by YOLOv8 for bounding box regression. Instead of predicting box coordinates, the model predicts a distribution for each coordinate. This encourages precise localization. The total loss is the weighted sum of all components, and the model learns by trying to minimize this total loss.

To evaluate the model performance, standard metrics such as precision, recall, average precision (AP), and mean average precision (mAP) are used.

Precision indicates the proportion of correctly predicted boxes, while recall indicates the proportion of real objects detected. Calculations are made using the terms true positive, false positive, and false negative.

Average Precision measures the area under the precision-recall curve for each class, while average average precision(mAP) is the average of AP across all classes.

mAP is reported based on specific IoU thresholds. mAP@0. 5 uses an IoU threshold to determine whether a predicted box is correct. The model’s test results showed mAP@0. 5 ≈ 0.74. mAP@0. 5:0. 95 is a more stringent criterion, requiring higher precision, and the model’s value on this metric was approximately 0.43. In summary, precision and recall together provide information about the reliability and completeness of the model.

4)Model Evaluation

The complexity matrix shows how well our model classifies smoke, fire, and background. Each row is normalized by the number of real examples for that class. For smoke detection, the model correctly predicted about %74 of real smoke examples, while the amount of smoke confused with fire is very low %1. However, almost a quarter of the smoke examples are not detected.

For fire detection, we correctly label %60 of the real fires. However, %40 of fires are not detected at all, which is our biggest source of error. For the background class, we only give one row of zeros, because the model cannot detect the background. The model is better at detecting smoke because the smoke columns are clearly visible. The confusion between classes is quite low, and errors are rare for smoke and fire.

Missed detections are our problem; not drawing a box around the real event, for example, can be dangerous for a forest fire, rather than false positives. So that,our next steps will include data augmentation focused on flames. We can enrich the training data to make small fires more representative. We also plan to lower the confidence threshold and revise the anchor box dimensions.

The aim is to learn with “hard negative” examples for the background and reduce false positives. Alternatively, it is possible to filter out fake detections using secondary classifiers. Analysis of the complexity matrix will reveal the strengths and weaknesses of our model, which will help identify targeted improvements.

5)Deploying Model with Gradio App

After creating a working model, a simple web application was developed using Gradio to make it easier to use. The application allows users to upload an image and watch the wildfire detection results in the browser.

In the application code, the YOLOv8 model is loaded and a function is defined that performs fire detection on an input image. This function displays the detection results with bounding boxes and labels; blue for smoke and cyan for fire. As a result, a string is returned indicating the image and the extraction time. Users can run the model by uploading an image, setting the confidence threshold and clicking the “Detect” button.

While testing the application, we found that the model is generally accurate. We can get fast results; the nano model runs very quickly on the GPU. We also thought of distributing the application to Hugging Face Spaces to reach a wider audience, so that everyone can try the wildfire detector in the web browser.

6)Conclusion

Developing a forest fire detection system with YOLOv8 strengthened our knowledge of object detection and provided valuable experience in contributing to environmental protection. The project helped us understand how these modern AI models can be applied to real-world problems and showed how to go from a trained model to a practical solution. There is room for improvement, but the progress achieved so far is not bad. AI-powered fire detection can be a reliable early warning system in the future. We can consider continuing the development of the project and implementing improvements in the future. The quality and quantity of data, transfer learning and training strategy were of great importance and can be improved in the future. Finally, this experience helped me understand the process of thinking about an AI solution for real-world implementation.


메타데이터
post_id
a7aa23da46ed
slug
wildfire-detection-with-yolov8-a7aa23da46ed
url
https://medium.com/@aydinmelih2344/wildfire-detection-with-yolov8-a7aa23da46ed
canonical_url
https://medium.com/@aydinmelih2344/wildfire-detection-with-yolov8-a7aa23da46ed
author_url
https://medium.com/@aydinmelih2344
status
ok
fetched_at
2026-08-06 19:45:59