darkflow - AttributeError: 'NoneType' object has no attribute 'find'

Viewed 862

new to darkflow and python. i am trying to train my own datasets by using https://github.com/thtrieu/darkflow and yolo weights. I'm currently having errors:

AttributeError: 'NoneType' object has no attribute 'find'

when executing pascal_voc_clean_xml.py line 41: 'w = (imsize.find('width').text) '

This is part of the code from https://github.com/thtrieu/darkflow/blob/master/darkflow/utils/pascal_voc_clean_xml.py:

in_file = open(file)
    tree=ET.parse(in_file)
    root = tree.getroot()
    jpg = str(root.find('filename').text)
    imsize = root.find('size')
    w = int(imsize.find('width').text)
    h = int(imsize.find('height').text)
    all = list()

    for obj in root.iter('object'):
            current = list()
            name = obj.find('name').text
            if name not in pick:
                    continue

            xmlbox = obj.find('bndbox')
            xn = int(float(xmlbox.find('xmin').text))
            xx = int(float(xmlbox.find('xmax').text))
            yn = int(float(xmlbox.find('ymin').text))
            yx = int(float(xmlbox.find('ymax').text))
            current = [name,xn,yn,xx,yx]
            all += [current]

    add = [[jpg, [w, h, all]]]
    dumps += add
    in_file.close()

and this is my xml file: enter image description here

I know that the 'find' is a function from ElementTree.py in python but why it the 'find' function does not work as it should be?

2 Answers

check your data in annotations(images folder)

for i, file in enumerate(annotations):

Maybe image00001.jpg 's xml file is no matter with your error code.

Some other xml file would not have attribute size or width.

Check your annotations, there must be few XML files in which width or height attribute would be 0. Rectify those.

Related