상세 컨텐츠

본문 제목

How to make annotation using VoTT

Bad print detector

by cpark40 2020. 2. 13. 15:21

본문

In order to learn model which needs bounding box,

it is necessary to tell directly which part of the data has which label.

It is often expressed in the form of coco style json.

 

Today, I want to talk about how to create your own annotation. 
Annotation means information such as the segmentation mask, 

box area and category of objects/people in the picture.
I will use the VoTT(Visual Object Tagging Tool) as a tool.

Visual Object Tagging Tool (vott)

 

[NOtE] Before you begin work, you should rename all image files to numbers. 

I recommend a program called 'darknamer' for easy change.

This work is very important.

 

 

Download the vott and create a new project. 

You can also add folders from your local directory.

You can add a tag by pressing the + button in the upper right corner. 
As shown in the image below, 

you can create a box in the desired location and select the appropriate tag, 

the box will be tagged. 
When all images are tagged, 

export the project by clicking the arrow button to the right of the Save button.

tagging
export button

 

export pascal voc

Press the left export button to set the provider as follows: Set the fascal VOC. 


[NOTE] If you have images that are not tagged,

it is best to erase them from the beginning,

otherwise you must select 'only tagged assets'. 

 

After export is finished, 

the PascalVOC-export folder will appear in the folder where the image is located.
Inside, there are Annotations, ImageSets, and JPEGImages.

If you look into Annotations, it contains xml files, 

which will now be converted into of the coco style json.

 

Fortunately, you can find Python code in the address of the Githeub below,

which turns the xml file into a coco style json.

Download the 'voc2coco.py'.

https://github.com/shiyemin/voc2coco

 

shiyemin/voc2coco

Convert pascol voc annotation xml to COCO json format. - shiyemin/voc2coco

github.com

You need a txt file containing a list of xml files in the annotations before you can execute the code.

Simply execute the following code to obtain it.

import xml.etree.ElementTree as elemTree
from os import listdir
from os.path import isfile, join

data_path = 'enter your xml file path'
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path,f))]
print(onlyfiles)

You can make txt files like this.

example of xmllist.txt

Now, everything is ready to create the coco style json file. 
Open the cmd and enter the following command:

 

[NOTE] The code execution location is where voc2coco.py is located, 

and the xmlllist.txt file must exist in the same location. 
At the end, write the name of the desired json file.

python voc2coco.py xmllist.txt [DIRECTORY OF ANNOTATIONS] dataset.json

 

 

The following json file can be generated as a result of execution.

{
  "images": [
    {
      "file_name": "00001.jpg",
      "height": 762,
      "width": 1073,
      "id": 1
    },
    {
      "file_name": "00002.jpg",
      "height": 828,
      "width": 1469,
      "id": 2
    },
    {
      "file_name": "00003.jpg",
      "height": 762,
      "width": 1073,
      "id": 3
    }
    ],
  "type": "instances",
  "annotations": [
    {
      "area": 97722,
      "iscrowd": 0,
      "image_id": 1,
      "bbox": [ 106, 176, 549, 178 ],
      "category_id": 0,
      "id": 1,
      "ignore": 0,
      "segmentation": []
    },
    {
      "area": 29694,
      "iscrowd": 0,
      "image_id": 2,
      "bbox": [ 400, 389, 202, 147 ],
      "category_id": 0,
      "id": 2,
      "ignore": 0,
      "segmentation": []
    },
    {
      "area": 104422,
      "iscrowd": 0,
      "image_id": 2,
      "bbox": [ 671, 418, 479, 218 ],
      "category_id": 0,
      "id": 3,
      "ignore": 0,
      "segmentation": []
    }
    ], 
     "categories": [{"supercategory": "none", "id": 0, "name": "bad"}]}

 

 

[In addition]

If an error occurs while trying the same way as this text, please check the NOTE again.