用pascal voc数据格式,mmdetection训练模型时报错AttributeError: 'NoneType' object has no attribute 'text',定位在xml_style.py-----> difficult = int(obj.find('difficult').text)
原因是标注文件 .xml的<object>没有<difficult>的标签。difficlut表明这个待检测目标很难识别,有可能是虽然视觉上很清楚,但是没有上下文的话还是很难确认它属于哪个分类;标为difficult的目标在测试成绩的评估中一般会被忽略
<annotation>
<folder>Pictures</folder>
<filename>0000009224.jpg</filename>
<path>/home/user/Pictures/0000009224.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>1440</width>
<height>1080</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>82110</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult> #缺少这个标签
<bndbox>
<xmin>233</xmin>
<ymin>388</ymin>
<xmax>460</xmax>
<ymax>593</ymax>
</bndbox>
</object>
<object>
<name>82110</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1039</xmin>
<ymin>398</ymin>
<xmax>1268</xmax>
<ymax>611</ymax>
</bndbox>
</object>
</annotation>
解决方法:
1. 可以查找.xml标注文件,把没有difficlut标签的补上。
2. 由于我的标签数据非常多,所有都添加上difficult的话非常耗时。如果数据没有特别难分的类别,可以忽略这个标签,在代码里把difficlut置为1。在 xml_style.py,修改如下:
if obj.find('difficult'):
difficult = int(obj.find('difficult').text)
else:
difficult = 0