模型训练报错AttributeError: ‘NoneType‘ object has no attribute ‘text‘

用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

  • 24
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值