Potholes Object Detection On the Basis Of Types (Real-time Using Yolov3)

Manoj Sisodia
Nov 7 · 5 min read

For Installation read my blog:

Potholes Detection

The YOLO framework (You Only Look Once) on the other hand, deals with object detection in a different way. It takes the entire image in a single instance and predicts the bounding box coordinates and class probabilities for these boxes. The biggest advantage of using YOLO is its superb speed — it’s incredibly fast and can process 45 frames per second. YOLO also understands generalized object representation.

How Does YOLO Work?

YOLO divides up the image into a grid of 13 by 13 cells: Each of these cells is responsible for predicting 5 bounding boxes. A bounding box describes the rectangle that encloses an object. YOLO also outputs a confidence score that tells us how certain it is that the predicted bounding box actually encloses some object.

Prior detection systems repurpose classifiers or localizers to perform detection. They apply the model to an image at multiple locations and scales. High scoring regions of the image are considered detections.

YOLO uses a totally different approach. It applies a single neural network to the full image. This network divides the image into regions and predicts bounding boxes and probabilities for each region. These bounding boxes are weighted by the predicted probabilities.

YOLO V3 is more accurate. The following picture depicts the overall architecture for YOLO V3:

Where to Get YOLO

YOLO binaries (and sources) can be downloaded from the following sources:

YOLO is based on the darknet, built in C. Darknet is an open source neural network framework written in C and CUDA.

How to Use YOLO

I) Clone the Repository

git clone https://github.com/pjreddie/darknet

II) Compile the Source

We can directly compile the source using make. Just go to the directory where darknet is cloned and run the command:

https://github.com/pjreddie/darknet

Remember: Make makes use of the Makefile, which consists of instructions to compile the C source files.

After completion of the make process, you will get a file named darknet, which is a binary and executable file. You can use this binary executable to run the YOLO.

III) Make darknet Executable

While running the command ./darknet, if you are getting permission error, it means the user does not have exeutable permission for running the binary. Just hit the following command:

chmod u+x darknet

After this, you will be able to run the darknet executable

YOLO Structure

I) Configuration Files

YOLO is entirely plug-n-play, that is, you can configure YOLO to detect any type of objects. In fact, you can also modify the CNN architecture itself and play around with it. YOLO does this by making use of configuration files under cfg/. The configuration files end with .cfg extension, which YOLO can parse.

These configuration files consist of mainly:

  • CNN Architectures (layers and activations)
  • Anchor Boxes
  • Number of classes
  • Learning Rate
  • Optimization Technique
  • input size
  • probability score threshold
  • batch sizes

Based on different versions, there can be many configurations from V1 to V3 to full training to tiny layers. You can download different configurations out of which following are the two:

II) Weights

Each configuration has corresponding pre-trained weights. Here, only YOLO V3 is referenced.

To get full weights for YOLO V3, download it from https://pjreddie.com/media/files/yolov3.weights
This is the weight trained on full 9000+ classes.

This is the weight trained on only 80 classes. You can get the weight for YOLO V3 from here https://pjreddie.com/media/files/yolov3-tiny.weights

Test YOLO

As told earlier, everything is run using the darknet exeutable file. Suppose we have an image named test.jpeg, then we can try predicting the objects as:

./darknet detect yolov3-tiny.cfg yolov3-tiny.weights test.jpeg

Normally, .cfg are inside cfg/ directory. Suppose you have the yolov3-tiny inside the directory weights/, then the command will be:

./darknet detect cfg/yolov3-tiny.cfg weights/yolov3-tiny.weights test.jpeg

Once done, there will be an image named predictions.jpeg in the same directory as of darknet file. You can view the prediction classes along with corresponding bounding boxes.

Train

The training is a bit more complex because we have to get things and configurations right. The following command does everything:

./darknet detector train custom/cfg/obj.data custom/cfg/tiny-yolo.cfg custom/tiny-yolo_100.weights

Training Command Breakdown

Here, .cfg and .weights are what they are meant to be — configurations and weight files as mentioned earlier. Everything happens using the obj.data file, which has content like:

classes= 1train  = custom/cfg/train.txtvalid  = custom/cfg/test.txtnames = obj.namesbackup = backup/

This file consists of a list of class names. Example:

catdogbackgroundbike

This file consists of a list of training images that we are going to feed into the network. The content is similar:

custom/train-images/11.jpgcustom/train-images/12.jpgcustom/train-images/13.jpg......

Here, train-images/ consists of all the training images. Along with the images, this directory also consists of a text file for bounding box corresponding to the image.
So, you will have custom/train-images/11.txt whose content can be:

0 0.32502480158730157 0.3950066137566138 0.12896825396825398 0.09523809523809523

Here, the first number represents the id or class of corresponding in obj.names. The remaining numbers represent the bounding box. If there were multiple boxes of multiple classes, it’d be like:

0 0.32502480158730157 0.3950066137566138 0.12896825396825398 0.095238095238095230 0.52502480158730157 0.3950066137566138 0.12896825396825398 0.095238095238095231 0.32502480158730157 0.3950066137566138 0.12896825396825398 0.09523809523809523

This file consists of a list of test images.

My training and weights for Potholes are converted in Keras are below :
>>Pothole Severity Low
>>Pothole Severity Medium
>>Pothole Severity High

For Yolo configure file and weights link:
Click To Download
Data was collected through Indian roads and was trained on h5 model file and configure file for three objects Low, Medium, and High.This provides the conditioning and accidents safety mechanism task by detecting and identifying the potholes on roads.

Check whole Project on My Repository
https://github.com/Kiesh/PotholeDetection.git

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade