Python script for converting Pascal VOC XML annotation files to normalized YOLO TXT annotation files
-
Create a file called name.txt with the class names separated by newlines.
-
Put both the name.txt and convert.py files in the folder containing the XML annotation files.
-
Run the script
python convert.py
-
If the script runs into any invalid xml file, names of the files can be found in invalid_files.txt
<annotation>
<folder>Images</folder>
<filename>02_Motijheel_280714_0005.jpg</filename>
<path>E:\Datasets\Dataset\Images\02_Motijheel_280714_0005.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1200</width>
<height>800</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>bus</name>
<pose>Unspecified</pose>
<truncated>1</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>833</xmin>
<ymin>390</ymin>
<xmax>1087</xmax>
<ymax>800</ymax>
</bndbox>
</object>
<object>
<name>bus</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>901</xmin>
<ymin>284</ymin>
<xmax>1018</xmax>
<ymax>395</ymax>
</bndbox>
</object>
</annotation>
0 0.8 0.764375 0.21166666666666667 0.55375
0 0.7995833333333333 0.740625 0.0975 0.77125