Skip to main content

YOLOv5 Wildfire Smoke Detection With Roboflow and Weights & Biases

In this article, we explore how to augment and annotate data with Roboflow and train a model with that data on Weights & Biases for wildfire smoke detection.
Created on July 26|Last edited on January 18

Today, we're going to combine Roboflow, Weights & Biases, and YOLOv5 to detect wildfire smoke in nature images.
Since at least 50% of the work training computer vision models lies in data preparation, we'll be using Roboflow for this important first step. Roboflow made annotating, prepping, augmenting, and managing computer vision datasets really simple, and it definitely sped up our process.
The other half of our work is the rigorous process of optimizing the architecture of our network and trying to squeeze the most accuracy out of it. Here, we'll use Weights & Biases to track our experiments and analyze model predictions. Luckily for us, W&B is closely integrated with YOLOv5, so the two play really well together.
Here's what we'll go over:

Table of Contents


Let's get started with our project!

Getting the Data

Normally, the process of getting data can be quite tricky and daunting, especially for more niche tasks. Roboflow has us covered. Specifically, we're talking about Roboflow Universe, which is their platform for hosting public datasets. Most importantly, for our purposes? This dataset is already annotated, so we don't have to go through the process of sourcing annotations or doing them ourselves.
The one we'll be using today is this dataset with images of wildfire smoke. Here's a quick example of a single data point:

Note that Roboflow may ask you to sign up for an account before you download the dataset, and having an account will help with more things that I'll be showing in the report below.
💡
Our first order of business is downloading the dataset to my PC locally. To do that, we'll head to Roboflow's project page and create a new project on their website titled Wildfire Smoke Detection with YOLOv5 and W&B.

Next, we'll drag & drop the folder with our images and labels into the Roboflow project, which gives us the public dataset uploaded to the Roboflow project:

Where this starts to get really valuable is when we get to the preprocessing & augmentation parts of our pipeline. Let's head there now:

Data Preprocessing and Annotation

One of the best parts of the Roboflow experience was seeing how their tool handled annotating new images within their UI. It was legitimately satisfying to use.
Adding new data is, of course, part and parcel of a lot of ML projects. For this example, I'm going to expand our dataset of wildfire images with a pair of images I found scouring the internet. That experience looks like this:

Once these are uploaded, we can immediately jump into annotating these images! The images that already have annotations don't show up in this menu at all, which is really useful and a nice quality-of-life experience. We can simply focus on the images that need annotating.


Data Augmentation and Preprocessing

Now, we can go into the Generate tab to generate a new version of our dataset. We'll apply some common preprocessing, such as resizing our images to be 416x416 (which is a common YOLO network image resolution).

Much like adding new data, And now we can jump to probably my favorite part of using Roboflow for dataset prep: data augmentation.

Augmentation is, of course, a popular way to increase your amount of training data. But not every augmentation technique is appropriate for every image type. For example, you may want to zoom into an image with text, but flipping it creates backward text that we don't need our model to understand. Thankfully, Roboflow gives us the choice as to what type of augmentation to apply to our images.
When performing augmentation, the rule of thumb that I use is asking myself whether as a human looking at an image, I'd be able to detect an object as the neural network will try to with that augmentation present.
💡

For example, in the example above, we're performing a horizontal flip, and the images themselves are human "readable." They make sense.
The second rule of thumb when augmenting data that I use is thinking about what the model will have to look once it's deployed. For example, since the images we expect our model to run the detection on will be normal images with ground at the bottom and the sky at the top, I'm not going to apply vertical flip turn the image upside-down, for example.
💡
For our project here, we can apply a couple of other solid augmentation techniques:


And by the end of it, we can see the augmentation techniques that I've chosen in Roboflow's UI.

Now, we can click "Generate" to generate a new dataset version with the preprocessing and augmentation techniques we've chosen.


Training

Now we're pretty much all set to jump into training. I'm going to perform training inside a Google Colab notebook. Getting our data into the notebook from Roboflow is as simple as clicking Export and choosing the export option:

We're going to go with a terminal command which downloads the dataset (perfect for when you're doing training somewhere in the cloud - like inside a Google Colab notebook), as you can directly download your data there.
In fact, you can follow along with the code by running it on Google Colab. 




The Code

Next, we'll git clone YOLOv5, download our data from Roboflow, and install wandb, which is the Weights & Biases Python client.
%%capture
!git clone https://github.com/ultralytics/yolov5.git
!curl -L "https://app.roboflow.com/ds/5F7B42TQI7?key=VhVxco4lnb" > roboflow.zip; unzip roboflow.zip; rm roboflow.zip
%cd /content/yolov5
!pip install -r requirements.txt
!pip install "wandb==0.12.10"
Then, all we have to do to jump into training is define for YOLOv5 the path to our data, the number of epochs to train for, and to what W&B project to log our experiments. In our case, it's yolov5-roboflow-wandb.
!python train.py \
--data ../data.yaml \
--epochs 10 \
--project yolov5-roboflow-wandb \
--upload_dataset \
--bbox_interval 1 \
--save-period 1
When you start training, you'll see something like this:

But because YOLOv5 and W&B are so closely integrated, you can click on your run link and navigate to your W&B Dashboard, which is much nicer to visually explore and better understand the training process.

This looks a lot nicer, doesn't it?


YOLOv5 and Weights & Biases Integration

This integration offers many amazing functionalities for using YOLOv5 and W&B together. Some of my favorites:
  • Ability to resume crashed runs
  • Bounding Box debugger to interactively model predictions on validation data
  • W&B Table showing predictions on val data against ground truth
  • Interactive training metrics
  • Saving checkpoint weights during training as Artifacts
Note: because it's an integration, all you have to do is to just authenticate into your W&B account and run your YOLOv5 training experiments. You'll get access to all of these functionalities without needing to write any code for them specifically.
💡
If you want to learn more about the training YOLOv5 and Weights & Biases, I've created a series of videos you might enjoy. 

Interactively Exploring Training Metrics of Our Wildfire Smoke Detection Model

Here are the metrics from the two different training runs, the first for 3 epochs and the second for 10 epochs. Loss is going down, MAP (or mean average precision) going up. What more could we ask for?



Visualizing Model Predictions on Validation Data With W&B Tables

Oftentimes, the best way to explore the model predictions is to actually look at what the model is predicting. W&B Tables is a great tool for exactly that. It allows us to interactively compare side-by-side the ground truth validation dataset images and what our model is predicting on these validation images.
Feel free to click around!



Conclusion

In this article, we learned about how to train a wildfire smoke detection YOLOv5 neural network using Roboflow to prepare our data and Weights & Biases to analyze our training experiments. And you can follow along with the code on Google Colab. 
You can learn more about Roboflow's features here, and if you'd like to learn more about training YOLOv5 with Weights & Biases, feel free to check out the video series I've created.


Iterate on AI agents and models faster. Try Weights & Biases today.