How to create custom dataset for object detection using LabelImg

Sandali Thissera
4 min readOct 28, 2022

--

Introduction.

Computer vision is a sub field of Artificial Intelligence which is mainly train computers and systems to gain information from images and videos. Main computer vision types are object detection, image classification, facial recognition, image segmentation, feature matching, pattern identification, etc. Computer vision simplifies the work for human such as self-driving cars, disease diagnosis, and many more.

Object detection is the most popular stream in Computer Vision. Computer vision is mainly applied when we are trying to solve real-world problem scenarios using images and videos. It has many different scenarios where custom object detection is needed such as manufacturing, e-commerce, aviation, etc.

Data annotation takes a major part of machine learning pipeline and this can be describe as the main step of dataset creation. But data annotation is a manual task and it consumes lot of time. There are lot of open source data annotation tools such as:

  • CVAT (Computer Vision Annotation)
  • LabelImg
  • Label Studio
  • VGG Image Annotator
  • COCO Annotator
  • Make Sense

Format Types of annotation tools:

  • txt
  • csv
  • image masks
  • TFRecords
  • COCO JSONs
  • Pascal VOC
  • XMLs

In this article, we will discuss how to use a custom dataset for object detection using LabelImg.

Image collection and Labeling

Before starting the image labeling we need to collect our dataset. Here, we are using food images as our dataset. And then identify the texts that need labeling. For installation procedure, you may require some command line skills along with Anaconda or python commands.

Detailed installation guide at GitHub : LabelImg Guide in Github

1.1 Install LabelImg using PIP command

First create a virtual environment and activate it using command line.

py -m pip install — user virtualenv

Then activate it.

activate virtualenv

Then perform following commands to install LabelImg.

pip install labelImg

Run following code to run the LabelImg:

labelImg

Then you’ll get the following window.

Figure 1.1 — LabelImg Interface

Then select the open Dir icon and choose the the image directory.

Figure 1.2 — Add image to the labelImg

Using the change save format you can choose the format of the annotation file. Following formats are available in LabelImg.

  • Pascal VOC
  • YOLO
  • CreateML

After selecting the annotation format then click on the create RectBox icon and then it will appear the cursor to draw a rectangle around the object.

Draw a rectangle for cover whole object you are interested. Then Label box will appear as follows. Then put the label name as you want and verify the image.

Figure 1.3 — annotate image and add the label

Then save and verify the image. Then use Next image icon for annotate the all the images. Repeat the same steps for all the images and annotate them according to your labels.

Finally you will get the saved folder along with the images and xml files for images.

Figure 1.4 — Images with annotation files

Then create the label map. If you’re using TensorFlow, it requires a label map, which namely maps each of the used labels to an integer values. This label map is used both by the training and detection processes. The label map will looks like as follows:

item {
id: 1
name: ‘burgers’
}
item {
id: 2
name: ‘chicken_wings’
}
item {
id: 3
name: ‘mac_and_cheese’
}

After finishing all of these you will successfully create the custom dataset for object detection training.

Here shows an example after applying image for object detection.

Figure 1.5 — Before detect object
Figure 1.6 — Object detection with annotations

Best practices

  1. Draw the bounding box to fit to entire object and try to make it as small as possible.
  2. Make complete annotation along with the label.
  3. Try to draw the bounding box in full view.

Limitations of LabelImg

  • Allow only the rectangular bounding box annotations.
  • Only support for three types of formats.
  • Image masks, Image tagging, Key point tagging is not allowed.
  • Not support for data augmentation and image manipulation.

So it’s simple!. Let us know your opinion as well.

Happy learnings!

--

--