在通过图像标记工具 labelimg对图像中的目标进行标记时,有时候会存在误标记的情况,需要找到无标记的序列,查找程序如下所示:
import os,cv2
import numpy as np
import xml.etree.ElementTree as ET
def getClass(xm):
tree = ET.ElementTree(file = xm)
root = tree.getroot()
objectset = root.findall('object')
cnt = 0
objName = []
if len(objectset):
for object0 in objectset:
objName.append(object0.find('name').text)
cnt = cnt + 1
else:
objName = 'background'
return objName
cc = 0
class_name = ['Yun5','Ganrao','w']
class_cnt =[0 for k in range(len(class_name))]
print('class_cnt',class_cnt)
xml_path_in = "/media/caffe-ssd/VOCdevkit/VOC2007/Annotations/"
a = 0
for xm in os.listdir(xml_path_in):
cc = cc +1
cls_name = getClass(xml_path_in + xm)
for cls_name0 in cls_name:
for i in range(len(class_name)):
if(cls_name0 == class_name[i]):
a = i
else:
if cls_name0 == 'name1w':
print('name1w',xm)
elif cls_name0 == 'name2w':
print('name2w',xm)
elif cls_name0 == 'nam4':
print('nam4',xm)
elif cls_name0 == 'neme3':
print('neme3',xm)
if a==2:
print('other',xm)
print('class_name',class_name)
print('class_cnt',class_cnt)
print('num:',np.sum(class_cnt))
|