Skip to content

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

@chAwater

Description

@chAwater

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions