批量修改labellmg的xml标注文件的标注名称
比如将标注B改为bacimport osimport globfrom xml.etree.ElementTree import parse, Elementseq_dir = os.path.expanduser('./')#xml文件所在位置img_files=glob.glob(seq_dir + '*.xml')forfile in files:dom = parse(img_file)r
·
比如将标注B改为bac
import os
import glob
from xml.etree.ElementTree import parse, Element
seq_dir = os.path.expanduser('./')#xml文件所在位置
img_files=glob.glob(seq_dir + '*.xml')
for file in files:
dom = parse(img_file)
root = dom.getroot()
# print(root)
for obj in root.iter('object'):#name节点
name = obj.find('name').text
if name == 'B':
name = 'bac'
if name == 'C':
name = 'cas'
if name == 'A':
name = 'pro'
obj.find('name').text = name #修改
# print(name1)
dom.write(img_file, xml_declaration=True)#将修改后的保存
更多推荐
所有评论(0)