avatarPranjal Saxena

Summary

The web content outlines a method for automating the labeling process in data augmentation for custom object detection tasks, using Jupyter Notebook to apply transformations to both images and labels simultaneously.

Abstract

The article discusses the application of data augmentation in custom object detection, highlighting the challenge of labeling a large number of augmented images. It introduces a technique to automate the labeling process by applying transformations to both the images and their corresponding labels. The author provides a tutorial using Jupyter Notebook, where code snippets are used to perform image rotations and bounding box adjustments without the need for manual relabeling. This approach significantly increases the diversity of training data for machine learning models, particularly for object detection tasks, without the laborious effort of re-annotating each new image. The article also includes links to external resources, such as the Anaconda distribution for Jupyter Notebooks, and demonstrates the process with embedded Gist code snippets and a YouTube video tutorial. The conclusion emphasizes the effectiveness of this method in generating a substantial dataset from a smaller initial set, thereby enhancing model accuracy.

Opinions

  • The author expresses the inefficiency of manually relabeling each augmented image, suggesting it as an impractical approach.
  • There is a clear endorsement of using Jupyter Notebooks for training machine learning models, particularly due to their interactive nature and the ability to run code snippets.
  • The author believes that automating the data augmentation process for object detection is not only feasible but also essential for improving model performance.
  • The article promotes the use of custom images for data augmentation to achieve better accuracy in object detection models.
  • The author encourages readers to support their work by becoming Medium members through their referral link, indicating that such support motivates them to produce more content.

Data Augmentation for Custom Object Detection

Data Augmentation Steps for Custom Object Detection

Image by Author

So, If you are here then you might be enthusiast towards learning data augmentation, Object detection, machine learning, deep learning or image processing. And, you might have worked on image classification task where you might have done the data augmentation steps.

But, In Case of object detection, We have to draw bounding boxes for all the images. And, If we will apply the data augmentation steps then the number of images will increase and then again we need to do the labeling for those images. These is a method I will cover in this article how you can automate the labeling steps for augmented images.

What is “Data Augmentation” ?

Data augmentation is a strategy that enables practitioners to significantly increase the diversity of data available for training models, without actually collecting new data. Data augmentation techniques such as cropping, padding, and horizontal flipping are commonly used to train large neural networks.

We now have idea what is data augmentation.

If you have worked on data augmentation in Image Classification problems you might aware of some data augmentation steps like:

  • Image Rotation
  • Add Noise
  • Image Flipping
  • And, many others are there

Now, you might have thought how we can use these techniques for Object detection?? hmm The challenge is :

  • Yes, we can try these mentioned methods and then we can again do the image labeling for all the newly created image. But, Seriously? are you going to repeat those labeling process for all the same but altered images? Big NO

So, here is a way:

  • Why not we can just apply transformation for both the images and labels together? BOOM!! Yes, we will do the same transformation for image and label.

How

In this tutorial, we will use Jupyter Notebook to train our model. In the Jupyter Notebook, we can run a set of code snippets and get the output we want.

Installing Jupyter Notebook

Jupyter Notebooks are a part of Anaconda distribution and are open-source Use this link for installation. During installation it will ask for adding notebook to environment variable, I would suggest to check that checkbox.

After installation is complete, open the Anaconda prompt and type “Jupyter notebook”, and it will launch a Jupyter Notebook in your browser.

Jupyter Notebook

Click on “new” to open your new Python Notebook.

Converting yolo format to opencv

Below function will help us converting Yolo format label to opencv, It will help in rotating bounding boxes.

Converting opencv format to yolo

After rotating the bounding boxed, we need to return back the yolo formatted label for our object detection model training. We will use the below function for it.

Rotating Images with Their Bounding Boxes

The below functions will help in rotating both image and bounding boxes.

Running all the defined functions and class

Now, we will call out methods to do the task. Here, I am using Image Rotation. Other augmentation methods can be as usual.

Demo Video

Conclusion

So, here it is we have used 250 images to create 1400 images for Yolov4 without creating bounding box for all the augmented images. :) You can use your custom images and increase the image count with their labels for better accuracy.

Before you go…

If you liked this article and want to stay tuned with more exciting articles on Python & Data Science — do consider becoming a medium member by clicking here https://pranjalai.medium.com/membership.

Please do consider signing up using my referral link. In this way, the portion of the membership fee goes to me, which motivates me to write more exciting stuff on Python and Data Science.

Also, feel free to subscribe to my free newsletter: Pranjal’s Newsletter.

Data Science
Data Scientist
Image Classification
Object Detection
Yolo
Recommended from ReadMedium