Annotation using LabelImg Tool

Getting the coordinates ready for the ‘object identification model’ to learn from images.

ROHINTH S
3 min readJul 8, 2021

The task of annotating the images for the task of training a machine learning/deep learning model falls under the data preparation stage.
(Note :- These data will already be collected by means of camera/etc in the data collection phase )

You need to annotate(draw a bounding box) the object in every single frame.
Although there are many ways for object annotation. I have explained in brief about ‘LabelImg’ — Open source Annotation tool.

Saving the image data-set in a folder (Adding classes.txt)

  1. Copy all your photos/images/frames to be annotated into one folder
  2. Create a text file named ‘ classes.txt ’.
  3. Add all the desired labels/classes in this file in separate lines.
Example of some classes that can be added to text file

LabelImg — An open source tool for image annotation

An open source tool called labelImg is a tool that can be used for image annotation. You need to clone the repository in your computer and follow the instructions from the repository.

1) labelImg for annotation task

Clone labelImg GitHub repository to your local system.

  1. Open command prompt and move to the desired folder.
  2. Use ‘ git clone https://github.com/tzutalin/labelImg.git ’ command to clone the repository to your local system.
  3. Follow the instructions in repository to install the dependencies for your desired operating system.
  4. After the repository is cloned, the files will be listed in your local system.
    (We will be only working with data folder and ‘labelImg.py’ file, others are left untouched)
LabelImg Cloned to local system
  1. Move inside data folder.
  2. Open the ‘predefined_classes.txt’ and delete all the contents of the file.
  3. Now add your desired labels/classes(which you will be annotating in your images) in separate lines and save the file.
    (IMPORTANT :- This should be the same classes which was in the classes.txt file we created above in data-set folder)
ORIGINAL predefined_classes.txt
REPLACE IT WITH DESIRED LABEL/CLASSES

Now open ‘labelImg.py’ file (wait until labelImg -GUI gets opened)

The various options in labelImg tool
  1. Use ‘Open Dir’ option and open the saved data-set folder.
  2. Use ‘Create RectBox’ option to draw a bounding box around the object in the current image.
  3. You will be prompted to select a label for the object which is surrounded by current bounding box. Select the appropriate label/class.
  4. You can annotate multiple objects in a single image.
  5. You can see the list of objects annotated in right pane.
  6. Use the ‘Save’ option and save the generated text file(name of the text file will be same as the image name but with txt extension) in the same data-set folder.
  7. Repeat the same steps to annotate all the images.
Completed Dataset will look like this ( if the output path is the same as dataset path )

Don’t forgot to upload your completed data-set folder(consisting of both images and text files) to your google drive.
Pros:-
1. Backup from data loss.
2. Easy to import and work with data-set in ‘google colab’.

Useful links :-
1) labelImg GitHub repository
2) YouTube Reference

--

--

ROHINTH S
ROHINTH S

Written by ROHINTH S

Pursuing my BE in Computer Science and Engineering from Sri Ramakrishna Engineering College. Talks about Data Science, Artificial Intelligence & Technology.