YOLO v5转数据集时出现AttributeError: ‘ NoneType‘ object has no attribute ‘text ‘ 报错——解决办法

 VOC标签格式转yolo格式并划分训练集和测试集时,出现如下报错:

Traceback (most recent call Last) :

        File "XXX(运行文件路径)", line 134, in

                convert_ annotation( nameWithoutExtention) # convert Label

        File "XXX(运行文件路径)", line 50, in convert_ annotation

                difficult = obj. find( 'difficult' ) . text

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

Process finished with exit code 1    #表示文件代码运行失败报错

YOLO v5转数据集时出现AttributeError: ‘ NoneType‘ object has no attribute ‘text ‘ 报错——解决办法_第1张图片

 问题描述:在运行附件一(文末)所述代码用于 VOC标签格式转yolo格式并划分训练集和测试集时,出现如下报错:

difficult = obj. find( 'difficult' ) . text

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

或者:

name = obj. find( 'name' ) . text

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

VOCdevit中存放的标签只有部分实现了成功转化,并卡在了某一张出现了如上报错。

解决办法:

打开已经转化成功的yolo文件夹里面查看最后报错卡住的那张照片编号,在xml文件中打开,检查内容,删除多余的标签。

Example:

YOLO v5转数据集时出现AttributeError: ‘ NoneType‘ object has no attribute ‘text ‘ 报错——解决办法_第2张图片

1. 可以看到我当时是卡在第006972张图片,然说明这张图片的xml文件内容一定是出了问题的。

YOLO v5转数据集时出现AttributeError: ‘ NoneType‘ object has no attribute ‘text ‘ 报错——解决办法_第3张图片

2. 在Annotations文件夹中找到006972这张图片的标签(XML文件),双击打开,检查内容。

YOLO v5转数据集时出现AttributeError: ‘ NoneType‘ object has no attribute ‘text ‘ 报错——解决办法_第4张图片

3. 可以发现内容中,有多余的 标签:

4. 将其删除。

5. 重新运行py文件,发现报错消失,问题解决。

附件一:目标检测---数据集格式转化及训练集和验证集划分_didiaopao的博客-CSDN博客

你可能感兴趣的:(python,开发语言,后端)