Image Labelling for YOLO using YOLO Mark

Mehul Gupta
Data Science in your pocket
4 min readAug 24, 2019

--

YOLO(You Look Only Once) Object Detection algorithm is, in most of cases, a success story.YOLO has been amongst the fastest object detection algorithm with considerably good results. Though there is a catch!

The Training/Validation Data format.

The training/validation set has the following components:

  • Images with objects(that has to be detected)
  • Text file corresponding to each image has the following composition:

“Label_ID X_CENTER Y_CENTER WIDTH HEIGHT”

Let's decode this first

  • Label_ID is the numeric ID given to different classes that have to be determined to start from 0 i.e. if 3 classes have to be determined, cats, dogs, and monkeys, IDs can be 0,1,2.
  • X_CENTER is the X coordinate of the center of the object that has to be detected/Image_width
  • Y_CENTER is the Y coordinate of the center of the object that has to be detected/Image_height
  • WIDTH is the width of the object that has to be detected/Image_width
  • HEIGHT is the height of the object that has to be detected/Image_height

Hence all the values(except the ID) is in the range 0–1

If an image has more than 1 object, the text file has to be of the form

“Label_ID_1 X_CENTER Y_CENTER WIDTH HEIGHT”

“Label_ID_2 X_CENTER Y_CENTER WIDTH HEIGHT”

“Label_ID_3 X_CENTER Y_CENTER WIDTH HEIGHT”

i.e. a new line for each object in the same text file. The name has to be the same as the image name except for the extension. Example: if an image is abc.jpg, the text file is abc.txt

Now, to produce such labels/text files, the best tool present is YOLO_Mark from the developers of YOLO itself supporting such an output once the user annotates the image.

Note: Now to use YOLO, you need to use your local as installing it on a server won’t provide you with GUI support.

Follow the below steps:

If following the above steps does the job for you, you are amongst the lucky 5% of people as most of the people may need some more assistance.

In most cases, you might see some OpenCV-related error while executing {cmake .} or {make} like this even though you have OpenCV in your system

Could not find a package configuration file provided by “OpenCV” with any of the following names:

OpenCVConfig.cmake
opencv-config.cmake

To resolve this, you need to perform a couple of more steps:

You might also check by omitting -D parameters from CMake in case of any issues.

The error shouldn’t appear now(Hopefully!!)

Now, to mark your images:

  • Take up your images folder and move it to Yolo_mark/x64/Release/data and rename your folder as ‘img’.You have a choice to keep your folder name as it is, but this will require some changes in yolo_mark.cmd & to avoid this overhead, we will rename it.
  • Make changes in obj.data and obj.names file according to the problem.

obj.names: This includes the label names, each label entered in a new line. Remember that the IDs assigned are dependent on the order of label names mentioned in obj.names

obj.data: This holds information about Number_of_classes, Train & valid data location(relative to darknet directory), and backup folder location(where weights after training on yolo are saved). You might not need to create a train.txt as Yolo_Mark creates it for you on its own.

  • you should follow up with {cmake .},{make} & {./linux_mark.sh} for launching Yolo_mark.Remember to make linux_mark.sh executable by {chmod +x *.sh}

You should see something like this

Annotate the images according to your requirement and then

You Are Done For The Day!!!

Some points to remember:

  • Every command is executed on Command Line
  • This setup is Python 3 compatible
  • {} denotes CLI commands

--

--