Product

Forest Fire Detection and Segmentation using YOLOv7

In this article, we will guide you to build Forest Fire Detection and Segmentation using YOLOv7
Muhammad Rizwan Munawar
5 min

Forest Fire Detection and Segmentation using YOLOv7

Pre-Requisites

  • Python3 is installed on your Linux/Windows System.
  • Git needs to be installed on your Linux/Windows System.

Introduction

Wildfires are one of the costliest and deadliest natural disasters, causing damage to millions of hectares of forest resources. The rapidly evolving field of computer vision can help reduce or let know some necessary and urgent steps using state-of-the-art algorithms.

So, let's start; the steps this article covers are mentioned below.

  • Clone YOLOv7 Segmentation code from GitHub.
  • Install the packages that need to run YOLOv7 Segmentation.
  • Download YOLOv7 Segmentation weights for Segmentation and fine-tuning
  • Segmentation of Cars with Pre-trained weights
  • Dataset Info (More precise)
  • Setup Dataset folder
  • Creation of Configuration file
  • Start Training
  • Fire Detection and Segmentation with Custom weights

Clone YOLOv7 Segmentation code from GitHub.

Create a folder named "YOLOv7-segmentation". Open the terminal/ (Command Prompt) in that folder. Clone the YOLOv7 segmentation repository with the command mentioned below.

gitt-clone

I moved to the cloned folder and upgraded pip using the below command.

pip-install

Install the packages that need to run the YOLOv7 Segmentation

Now, it's time to install python packages that will help you to blur detected objects easily on your system. Use the command mentioned below to install packages.

pip-install

Download YOLOv7 Segmentation weights for Segmentation and fine-tuning

It's time to download YOLOv7 segmentation weights, which will help you segment objects in the video stream and can also be used for fine-tuning custom data.

Weights Download link: HERE

Segmentation of Cars with Pre-trained weights

Now you have installed requirements. It is time to verify that the packages are working fine by segmenting cars with pre-trained weights. You can use any video or image, whatever you want.

Cars with Pre-trained Weights

The output will look as shown below;

Car Detection

Dataset Info (More Precise)

The dataset has been taken from Roboflow and labeled by our team in segmentation format by following the link below.

Train YOLOv7 Segmentation on Custom Data!

If you are interested in getting a dataset, contact the Cameralyze team. Otherwise, you can take data from Roboflow by following mentioned link below.

https://public.roboflow.com/object-detection/wildfire-smoke

Setup Dataset Folder

Once you have the dataset, create a folder named "smoke-segmentation" inside {yolov7-segmentation/data} folder by following the shown structure below.

yolov7-segmentation

Creation of Configuration File

Create a file having the filename "fire. YAML" inside the "yolov7-segmentation/data" folder. Paste the shown lines below in that file.

train-yolov7-segmentation

Start Training

All your pre-processing and configuration steps are completed. Now you can run the command shown below in (terminal/command prompt) to start training on personal protective equipment data.

python3-segment

Note: Ensure your terminal path is set to the "YOLOv7-segmentation/yolov7-segmentation" folder.

Fire Detection and Segmentation with Custom weights

Once training finishes, you can run the show command below to detect and segment fire. For testing, you can use any video you want.

Fire Detection and Segmentation

Results Directory: [YOLOv7-segmentation/yolov7-segmentation/runs/predict/exp/]

Check Out Output Video

Creative AI Assistant

It's never been easy before!
Starts at $24.90/mo.
Free hands-on onboarding & support!
No limitation on generation!