training-datayolococovoc

How to convert PASCAL VOC to YOLO


I was trying to develop some way to convert annotations between formats, and it's quit hard to find information but here I have :

This one is PASCAL VOC

<width>800</width>
<height>450</height>
<depth>3</depth>
<bndbox>
    <xmin>474</xmin>
    <ymin>2</ymin>
    <xmax>726</xmax> <!-- shape_width = 252  -->
    <ymax>449</ymax> <!-- shape_height = 447 -->
</bndbox>

convert to YOLO darknet

2 0.750000 0.501111 0.315000 0.993333

note initial 2 it's a category


Solution

  • My classmates and I have created a python package called PyLabel to help others with this task and other labelling tasks.

    This would be the basic code to convert from voc to coco:

    !pip install pylabel
    from pylabel import importer
    dataset = importer.ImportVOC(path=PATH_TO_ANNOTATIONS)
    dataset.export.ExportToYoloV5()
    

    You can find sample notebooks and the source code here https://github.com/pylabel-project/pylabel