How to Train YOLO v7 on a Custom Dataset for Structural Damage Detection in Critical Infrastructure using Drones

In today’s article, we’ll show you how we at Theos AI successfully built an Artificial Intelligence model to monitor critical infrastructure in search of structural damage signs such as cracks and rebar exposures.

Example of Reinforcement Bar Exposure Detection in Damaged Infrastructure

This model could be used inside a drone that flies around critical infrastructure and detects structural damage signs in real-time and notifies the team responsible to go fix them as soon as possible before the structure falls down.

The Plan

Our structural damage detection system will need to detect all the cracks and rebar exposures in the frames streamed from the drone camera, and that can be done using a computer vision task called Object Detection.

Object detection models receive an image as input and return a list of detections as output, these detections are made up of the following information.

  • Class: the class name of the detected object, in our case it will be the “crack” and “rebar-exposure” classes.

  • Confidence: this is an estimation of how confident our AI model is at making this prediction. Confidence scores range from 0 to 1, zero meaning no confidence at all, and one meaning absolute certainty.

  • X: the x position of the object within the image.

  • Y: the y position of the object within the image.

  • Width: the width of the object.

  • Height: the height of the object.

The best object detection model at the time of this writing is YOLOv7, so that’s the one we’ll use for our damage detection drone.

In AI and Machine Learning, generally the larger the neural network (meaning it has many millions of artificial neurons), the better it performs. These models require quite a bit of computing power, therefore take longer to perform inference. We want our structural damage detection model to run as fast as possible, so we’ll use the smallest version of our chosen neural network: YOLOv7 tiny.

Let’s do it.

Following are the steps we’ll have to take to build our damage detection model.

  1. Collect example images similar to the ones that our AI will see live in the real-world.

  2. Label bounding boxes of all the objects of interest (cracks and rebar exposures) in all the example images.

  3. Train the model.

  4. Use this model in our damage detection drone.

Collecting Images

We don’t need many images to get a good working model, you should always start with just 100 images, train your AI and test it. We should take these images with the same camera that will be connected to our drone.

If it’s not working very well, just upload again a few more hundred images, label them and retrain. Repeat this process until you’re satisfied with your model. Think of it like an AI MVP (minimum viable product).

Here are some that I collected.

We should take images in various angles and light conditions if we plan for our damage detection drone to work well in all situations.

Labeling

To tell our AI what we want it to detect, we need to draw bounding boxes in all our example images.

We’re going to use the Theos AI to label our images.

Following are the steps we have to take.

  1. Sign up to a free Theos AI account.

  2. Create a new project.

  3. Create a new dataset.

  4. Upload our images to our dataset.

  5. Create the “crack” and “rebar-exposure” classes we want to detect.

  6. Start labeling our images.

Let’s go.

If you want to use the same dataset I used here, here’s the download link.

We’re now ready to train our AI model.

Training

In order to train our dataset with YOLOv7, we’ll need to follow these three simple steps.

  1. Connect a Google Colab instance to Theos in order to use a free GPU for training.

  2. Create a new training session with our desired neural network algorithm, in our case YOLOv7 tiny (the smallest YOLOv7 version), our dataset and the Google Colab machine that will do the training.

  3. Click the Start Training button and wait for our AI to finish training.

Now, let’s create a new training session.

The training completed succesfully!

We’re now ready to deploy our model to the cloud as a REST API.

Deployment

To deploy our trained object detection model we’ll follow these steps.

  1. Go to the deploy section of Theos.

  2. Create a new deployment by selecting the algorithm we used, YOLOv7 tiny, and selecting the best weights (weights is a file that encodes the knowledge of our AI model).

Let’s create a new deployment and test it inside the Playground.

Our AI model is working!

Now you can take a look at our Docs to learn how to use this model in a drone or any device of your choice.

The End

We did it!

I hope you enjoyed reading this as much as we enjoyed making it!

Consider joining our Discord Server where we can personally help you make your computer vision project successful!

Or you can also reach out to contact@theos.ai if you have any questions!

Previous
Previous

Real-time Object Detection + OCR using YOLO v7 in Google Colab Free GPU (ANPR / ALPR Tutorial 2023)

Next
Next

How to Train YOLO v7 on a Custom Dataset for Gun Detection in Security Cameras (Python Tutorial 2023)