python实现对LabelImg标注的xml文件修改其标签名字

‘’’
通过解析xml文件,批量修改xml文件里的标签名称,比如把标签zero改成num
‘’’
import os.path
import glob
import xml.etree.ElementTree as ET
path = r’D:/picture/Annotations/’
for xml_file in glob.glob(path + ‘/*.xml’):
####### 返回解析树
  tree = ET.parse(xml_file)
  ##########获取根节点
  root = tree.getroot()
  #######对所有目标进行解析
  for member in root.findall(‘object’):
    objectname = member.find(‘name’).text
     if objectname == ‘zero’:
        print(objectname)
        member.find(‘name’).text = str(‘num’)
        tree.write(xml_file)

你可能感兴趣的:(目标检测)