Git Product home page Git Product logo

xmltotxt's Introduction

XmlToTxt

ImageNet file xml format to Darknet text format. Works well with directories and subdirectories.

Installation

sudo pip install -r requirements.txt

Usage

python xmltotxt.py -c cls.txt -xml xml -out out

Mandatory arguments

-xml 

Optional arguments

-c, -out

Example

Input xml file.

<annotation>
	<filename>image-0000016.jpg</filename>
	<size>
		<width>1920</width>
		<height>1080</height>
	</size>
	<object>
		<name>sedan</name>
		<bndbox>
			<xmin>75</xmin>
			<ymin>190</ymin>
			<xmax>125</xmax>
			<ymax>210</ymax>
		</bndbox>
	</object>
</annotation>

Output text file.

5 0.052083 0.185185 0.026042 0.018519

Motivation

I used Darknet for real-time object detection and classification. Sometimes you need to collect your own training dataset for train your model. I collected training dataset images and fine awesome tool for labeling images. But it generates xml files. So I needed to implement tool which translates from ImageNet xml format to Darknet text format. Also compatible with latest YOLOv5 by Ultralytics.

xmltotxt's People

Contributors

dnjooiopa avatar isabek avatar shashwat1998 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

xmltotxt's Issues

Citation for this repo

Hi there,

I'm looking for a citation of this repo with bitex format for my thesis. Thanks so much!!

Support custom classes file

Need to set classes file as an optional argument.

python xmltotxt.py -c custom_classes.txt -xml xml -out out

Conversion Error : ZeroDivisionError: float division by zero

ERROR:root:('Missing required array: "objects"',)
Traceback (most recent call last):
File "xmltotxt.py", line 33, in
main()
File "xmltotxt.py", line 29, in main
transformer.transform()
File "/home/MyPc/Downloads/XmlToTxt/transformer.py", line 18, in transform
self.write_to_txt(annotations, classes)
File "/home/MyPc/Downloads/XmlToTxt/transformer.py", line 23, in write_to_txt
f.write(self.to_darknet_format(annotation, classes))
File "/home/MyPc/Downloads/XmlToTxt/transformer.py", line 31, in to_darknet_format
x, y, width, height = self.get_object_params(obj, annotation.size)
File "/home/MyPc/Downloads/XmlToTxt/transformer.py", line 48, in get_object_params
x = absolute_x / image_width
ZeroDivisionError: float division by zero

Can You Help me About this issue ? Thanks

output broken

running the base example only creates 1 file which also happens to be empty:

/dataSets/XmlToTxt$ python xmltotxt.py -xml xml -out out
Please, add 'sedan' to classes.txt file.
/dataSets/XmlToTxt$ ls out
image-0000001.txt

KeyError: 'person'

Traceback (most recent call last):
File "xmltotxt.py", line 33, in
main()
File "xmltotxt.py", line 29, in main
transformer.transform()
File "/home/ubuntu/ext/XmlToTxt/transformer.py", line 18, in transform
self.write_to_txt(annotations, classes)
File "/home/ubuntu/ext/XmlToTxt/transformer.py", line 23, in write_to_txt
f.write(self.to_darknet_format(annotation, classes))
File "/home/ubuntu/ext/XmlToTxt/transformer.py", line 29, in to_darknet_format
result.append("%d %.6f %.6f %.6f %.6f" % (classes[obj.name], x, y, width, height))
KeyError: 'person'

Didn't work for Korean characters (UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 7: character maps to <undefined>)

Hi Isabek,

I'm really thankful for you making this repo. However it didn't work for Korean characters, or I couldn't make it? Could you please check and update it (if possible). Here is the error when I'm running the code:

Traceback (most recent call last):
  File "xmltotxt.py", line 33, in <module>
    main()
  File "xmltotxt.py", line 29, in main
    transformer.transform()
  File "D:\Projects\XmlToTxt\transformer.py", line 15, in transform
    classes = reader.get_classes()
  File "D:\Projects\XmlToTxt\reader.py", line 18, in get_classes
    lines = f.readlines()
  File "C:\Users\Scott\Anaconda3\envs\xmltotxt\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 7: character maps to <undefined>

I'm guessing it might be an encoding issue. Thanks in advance!

ERROR:root:('Missing required array: "objects"',)

HI I got this error while running this code

ERROR:root:('Missing required array: "objects"',)

my .XMl file is like this

<?xml version="1.0"?>

-<annotation>

<folder>None</folder>

<filename>train/images/fruit_0_1.png</filename>

<path>None</path>


-<source>

<database>Unknown</database>

</source>


-<size>

<width>250</width>

<height>250</height>

<depth>3</depth>

</size>

<segmented>0</segmented>


-<object>

<name>oranges</name>

<pose/>

<truncated>0</truncated>

<difficult>0</difficult>


-<bndbox>

<xmin>56</xmin>

<ymin>106</ymin>

<xmax>73</xmax>

<ymax>123</ymax>

</bndbox>

</object>

</annotation>

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.