Tony607/voc2coco

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

Closed this issue · 3 comments

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!

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

image

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

  • This code seems to be NOT actively maintained
  • Fixed by #11 or #13