Skip to content

Annotations

Markus Fleischhacker edited this page Sep 21, 2020 · 3 revisions

Exporting annotations

To save all image annotations in your current session click File > Export Annotations. You can then choose between saving the annotations using the Pascal-VOC format... or the YOLO format... menu entries. Finally the program will ask you to specify the target folder for the annotation files.

Saving annotations in Pascal VOC format

If you choose Pascal-VOC format, the annotations will be saved as XML files. For every image that contains at least one bounding box (rectangular or polygonal), exactly one XML file will be created. The filename of annotation files follows the pattern:

<image-filename>_<image-file-extension>_A.xml

For example, the annotation file for an image file dummy.png would be named dummy_png_A.xml.
Sample annotation


Sample annotation

An annotation file containing the following data was produced after annotating a single image with 3 bounding boxes as in the image above and then clicking the File > Save Annotations... menu-item:

<annotation>
    <folder>Samples</folder>
    <filename>alexander-popov-Xbh_OGLRfUM-unsplash.jpg</filename>
    <size>
        <width>3000</width>
        <height>2000</height>
        <depth>3</depth>
    </size>
    <object>
        <name>Car</name>
        <difficult>0</difficult> 
        <occluded>0</occluded>
        <pose>Back</pose>
        <truncated>0</truncated>
        <actions>
            <driving>1</driving>
        </actions>
        <bndbox>
            <xmin>1000.22</xmin>
            <xmax>1258.07</xmax>
            <ymin>1272.39</ymin>
            <ymax>1487.27</ymax>
        </bndbox>
        <part>
            <name>Taillight</name>
            <difficult>0</difficult>
            <occluded>0</occluded>
            <pose>Unspecified</pose>
            <truncated>0</truncated>
            <bndbox>
                <xmin>1009.07</xmin>
                <xmax>1046.98</xmax>
                <ymin>1336.85</ymin>
                <ymax>1363.4</ymax>
            </bndbox>
        </part>
        <part>
            <name>Taillight</name>
            <difficult>0</difficult>
            <occluded>0</occluded>
            <pose>Unspecified</pose>
            <truncated>0</truncated>
            <bndbox>
                <xmin>1155.69</xmin>
                <xmax>1203.3</xmax>
                <ymin>1338.54</ymin>
                <ymax>1360.45</ymax>
            </bndbox>
        </part>
    </object>
</annotation>

Note: The actions element will only be added if the corresponding bounding box contains at least one action tag. The elements difficult, truncated, occluded and pose however will always be added and their values set to defaults ('0' for the first three, 'Unspecified' for the latter) if the corresponding tag was not assigned to the bounding box.

Saving annotations in YOLO format

Important: Only rectangular bounding boxes are exported when using YOLO format because (to my knowledge) the YOLO object detection system cannot handle general polygonal boxes. Also, object tags are not supported by the YOLO format and will simply be ignored during the export.

If you choose to export using YOLO format, the annotations will be saved to one .txt-file per image which will be given the same name as the corresponding image file. Each of these files contains descriptions for the rectangular bounding boxes (one per line) belonging to the image:

<object-class> <x> <y> <width> <height>

Here x, y, width and height are given relative to the images width and height (i. e. the values are between 0 and 1). object-class is an index into a list of category names which are written to a file called object.data.

Saving annotations in JSON format

If you choose to export to JSON format, all your created annotations will be save to a single .json file of your choosing.

Importing annotations

You can import existing image annotations from a folder containing annotation files in either the Pascal-VOC format or the YOLO format, by clicking File > Import Annotations > Pascal-VOC format.../YOLO format... and selecting the import-directory. If errors occur during the import-process, a dialog window will be displayed, showing you the files which could not be imported as well as a description of the errors. Some of the errors that could occur while loading an annotation from a file include:

  • The annotation file could not be opened.
  • The file contains data of an annotation to an image file which is not currently loaded in the application.
  • The annotation file does not conform to the expected format (e.g.: non-optional elements missing).

Pascal-VOC format specifics

When importing annotations from existing files, the following XML-elements are optional (No tags will be produced as a result of these lines):

<difficult>0</difficult>
<occluded>0</occluded>
<pose>Unspecified</pose>
<truncated>0</truncated>
<actions></actions>

All other elements occurring in the sample annotation XML-output are mandatory. Importing an XML-file with any missing mandatory elements will result in an error.

Note: Some annotation files, such as those contained in the Pascal VOC 2012 dataset, may contain additional XML-elements e.g.: source, database, image, segmented ... - currently these elements are ignored.