Code Monkey home page Code Monkey logo

yolo2pascal-annotation-conversion's Introduction

Yolo2Pascal-Annotation-Conversion

Perform conversion between YOLO annotation format and PASCAL VOC format and vice versa. Code based on LabelImage repo.

Usage:

  • Images must be in .jpg/.png format.
  • YOLO to PASCAL: The script will search for all .txt files in the folder and perform the conversion. Converted PASCAL annotation files have a .xml extension, reside in the same folder and share the same name with their corresponding images.
  • PASCAL to YOLO: The script will search for all .xml files in the folder and perform the conversion. The script requires a file class.txt describing all classes (this file is generated autonomously if using the LabelImage tool above for annotating images). Converted YOLO annotation files have a .txt extension, reside in the same folder and share the same name with their corresponding images.

Demo:

  • YOLO to PASCAL:
    • python3 yolo2pascal/yolo2voc.py demo/yolo2pascal
    • After this, 2 files cat.xml and dog.xml should appear in the demo/yolo2pascal folder. They are label files in PASCAL format. You can use LabelImage to load the directory using PASCAL format to check.
  • PASCAL to YOLO:
    • python3 pascal2yolo/voc2yolo.py demo/pascal2yolo
    • After this, 2 files cat.txt and dog.txt should appear in the demo/pascal2yolo folder. They are label files in YOLO format. You can use LabelImage to load the directory using YOLO format to check.
  • Example of class.txt file. They are just labels listed in an alphabetical order:
    • cat
    • dog

TODO:

  • Remove Qt dependency
  • Add support for different image formats (thanks guysoft)

yolo2pascal-annotation-conversion's People

Contributors

hai-h-nguyen avatar shapedo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

yolo2pascal-annotation-conversion's Issues

Got all zero <bndbox> in XML

Finished running demo, I got all zero bndbox in cat.xml & dog.xml...

<bndbox> <xmin>0</xmin> <ymin>0</ymin> <xmax>0</xmax> <ymax>0</ymax> </bndbox>

螢幕截圖 2020-09-26 18 07 14

ZeroDivisionError: float division by zero

input XML;

<annotation>
	<folder>TRAIN</folder>
	<filename>1451_1-2$8.jpeg</filename>
	<path>/Volumes/Samsung_T5/20201022_RNN_DMG_OS/data/IMG_LBLS/TRAIN/1451_1-2$8.jpeg</path>
	<source>
		<database>Unknown</database>
	</source>
	<size>
		<width>200</width>
		<height>238</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>
	<object>
		<name>1451_1-2</name>
		<pose>Unspecified</pose>
		<truncated>1</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>6</xmin>
			<ymin>1</ymin>
			<xmax>175</xmax>
			<ymax>231</ymax>
		</bndbox>
	</object>
</annotation>

stops running with the following error;

Convert 1451_1-2$8.xml
Image path: /volumes/Samsung_T5/IMG_LBLS/train/1451_1-2$8.jpg
Traceback (most recent call last):
  File "voc2yolo.py", line 57, in <module>
    writer.save(targetFile= imgFolderPath + "/" + annotation_no_xml + ".txt")
  File "/Users/oliviervandhuynslager/Documents/DarkNet/darknet/scripts/pascal2yolo/yolo_io.py", line 61, in save
    classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList)
  File "/Users/oliviervandhuynslager/Documents/DarkNet/darknet/scripts/pascal2yolo/yolo_io.py", line 37, in BndBox2YoloLine
    xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero

Qt dependency

I couldn't find how to remove the qt dependency. Any help ?

All values are zero in .xml file

Hi,

I used your code before without any problem. Now, I got zeros in .xml files.
Note: I used this command:
python yolo2pascal/yolo2voc.py demo/yolo2pascal
run with anaconda (pyhon 3.8.3)

cat_xml

png support

says the files must be in jpg, would png work?

Script not running

I followed the procedure.

used the following command

*python yolo2voc.py C:/Users/VVSB/Desktop/FLIR_Dataset/FLIR_ADAS_1_3/New folder/image C:/Users/VVSB/Desktop/FLIR_Dataset/FLIR_ADAS_1_3/New folder/Image/text

There is no Output.
python3 gives some error.

Thank you for support

Fix: Too many Values given expected 5

Hey,
i got an error when trying to convert yolo2pascal format.
Error: Too many Values given expected five.
It occurs in yolo_io.py in parseYoloFormat. So i looked your code up and found out that my yolo dataset had an " " after the 5 Values. If anyone runs into that Problem to you can fix it by editing yolo_io.py -> parseYoloFormat to:

try:
classIndex, xcen, ycen, w, h = bndBox.split(' ')
except Exception:
classIndex, xcen, ycen, w, h, corrupted = bndBox.split(' ')

the .split method is basically splitting the Complete txt file into pieces. If you happen to have " " at the end it needs 6 Values to be asigned. Thats why it's throwing the Error above. Now it works like a Charm thank you for providing that library.

Error with classes.txt file

HI,

I tried to convert yolo format to pascal format

I haev folder with images and .txt files

:txt file consist of : classID x y width height

I do not have classes.txt file with me..

what is that fiel for?

How it looks like?

Any help to create it manually.

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.