在目标检测任务中,标注数据可能会细分类别,训练又不想细分的情况,如在标注的时候标注了男人和女人变迁为“male”“female”,在训练时候不想区分男人或者女人,统一为人变迁 为“person”,这时候就需要对标注的标签进行修改。代码参考如下
import os
import xml.etree.ElementTree as ET
cnt = 0
with open('list.txt','r') as f:
for line in f.readlines():
line = line.strip()
xml_path = os.path.join('root/',line)
tree = ET.parse(xml_path)
root = tree.getroot()
for node in root.iter('name'):
node.text = 'person'
tree.write(xml_path)
cnt+=1
print(cnt)