Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Float coordinate cause error (ValueError: invalid literal for int() with base 10) #5

Closed
chAwater opened this issue Jun 17, 2020 · 3 comments

Comments

@chAwater
Copy link

Float in the coordinate will cause error:

Traceback (most recent call last):
  File "voc2coco.py", line 154, in <module>
    convert(xml_files, args.json_file)
  File "voc2coco.py", line 109, in convert
    ymin = int(get_and_check(bndbox, "ymin", 1).text) - 1
ValueError: invalid literal for int() with base 10: '281.70000076293945'

Code:

voc2coco/voc2coco.py

Lines 108 to 111 in 207f265

xmin = int(get_and_check(bndbox, "xmin", 1).text) - 1
ymin = int(get_and_check(bndbox, "ymin", 1).text) - 1
xmax = int(get_and_check(bndbox, "xmax", 1).text)
ymax = int(get_and_check(bndbox, "ymax", 1).text)

Not sure:

  • it is a general problem or not
  • why there are float in my VOC2012 dataset

Check float in xml files:

grep '<ymin>[0-9].*\.' $VOC_PATH/Annotations/*.xml | head
# In general
grep '<[xy]m[ia][nx]>[0-9]\{0,4\}\.'  $VOC_PATH/Annotations/*.xml | head

Result:

$VOC_PATH/Annotations/2011_003353.xml:			<ymin>45.70000076293945</ymin>
$VOC_PATH/Annotations/2011_006777.xml:			<ymin>281.70000076293945</ymin>

BTW: Great code and blogs! It helps me a lot!

@Mattis95
Copy link

I got the same issue. Generally speaking there shouldn't be floats in VOC files. I got floats, because i got my VOC files from converting yolo annotations to VOC. So I went back and rounded to a whole number while converting from yolo to VOC. That fixed it for me

@Pluto1314
Copy link

image

I just add float(). That fixed it for me.

@chAwater
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants