猿问

darkflow - AttributeError: 'NoneType' 对象没有属性

darkflow 和 python 的新手。我正在尝试使用https://github.com/thtrieu/darkflow和 yolo 权重来训练我自己的数据集。我目前遇到错误:


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

执行pascal_voc_clean_xml.py第 41 行时:'w = (imsize.find('width').text) '


这是来自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()

这是我的 xml 文件:

我知道'find'是python中ElementTree.py的一个函数,但为什么'find'函数不能正常工作?


PIPIONE
浏览 246回答 2
2回答

料青山看我应如是

检查注释中的数据(图像文件夹)for i, file in enumerate(annotations):也许 image00001.jpg 的 xml 文件与您的错误代码无关。其他一些 xml 文件不会有属性size或width.

烙印99

检查您的注释,必须有几个 XML 文件的宽度或高度属性为 0。纠正这些。
随时随地看视频慕课网APP

相关分类

Python
我要回答