TensorFlow训练错误:All bounding box coordinates must be in [0.0, 1.0]: 1.13308


错误表现:
在使用TensorFlow做目标检测时,训练自己的模型时候出现以下问题:

tensorflow.python.framework.errors_impl.InvalidArgumentError: 
All bounding box coordinates must be in [0.0, 1.0]: 1.13308
  • 数据集格式:PASCAL VOC

错误原因:(扩充后的)数据集的标注边界值超出了图像的边界


解决方法:自己写了一个脚本对xml标签文件检测,检测扩充后数据中哪些标签除了问题,对于出问题的标签和照片,才去替换或者重新标注的方法解决。

  • python版本检测代码如下:
import re
import os
import xml.etree.ElementTree as ET

#myself dataset path
annotation_folder = './VOC2012/Annotations/'			
list = os.listdir(annotation_folder)

def file_name(file_dir):
	L = []
	for root, dirs, files in os.walk(file_dir):
		for file in files:
			if os.path.splitext(file)[1] == '.xml':
				L.append(os.path.join(root, file))
	return L

count = 0
xml_dirs = file_name(annotation_folder)

for i in range(0, len(xml_dirs)):
	#print(xml_dirs[i])
	annotation_file = open(xml_dirs[i]).read()
	root = ET.fromstring(annotation_file)
	label = root.find('filename').text
	# print(label)
	count_label = count

	#get the pictures' width and height
	for size in root.findall('size'):	
		label_width = int(size.find('width').text)
		label_height = int(size.find('height').text)	

	#get the boundbox's width and height
	for obj in root.findall('object'):
		for bbox in obj.findall('bndbox'):
			label_xmin = int(bbox.find('xmin').text)
			label_ymin = int(bbox.find('ymin').text)
			label_xmax = int(bbox.find('xmax').text)
			label_ymax = int(bbox.find('ymax').text)
			if label_xmin<0 or label_xmax>label_width or label_ymin<0 or label_ymax>label_height:		
				#judge the filename is not repeat
				if label_temp == label:
					continue
				print('--'*30)
				print(xml_dirs[i])   #print the xml's filename
				#print(label)
				print("width:",label_width)
				print("height:",label_height)
				print(label_xmin,label_ymin,label_xmax,label_ymax)
				print('--'*30)
				count = count+1
		label_temp = label

print("================================")
print(count)

找出界面展示:

------------------------------------------------------------
./VOC2012/Annotations/_01_001337.xml
width: 244
height: 365
209 49 269 104
------------------------------------------------------------
================================
2615

可以看到输出了所有的错误文件名称、图片的长宽高、标签的值以及问题照片总数。
此处由于本人扩增的标签数据出现问题的太多,故选择重新扩充,若果出现问题的照片数较少,可以手动解决。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值