代码功能:删除除了猫狗的其他类的标签框,新的xml保存在1文件夹下.
import xml.etree.cElementTree as ET
import os
path_root = ['./Annotations']
CLASSES = ["cat","dog"]
for anno_path in path_root:
xml_list = os.listdir(anno_path)
for axml in xml_list:
path_xml = os.path.join(anno_path, axml)
tree = ET.parse(path_xml)
root = tree.getroot()
for child in root.findall('object'):
name = child.find('name').text
if not name in CLASSES:
root.remove(child)
tree.write(os.path.join('./1', axml))
可使用下面代码查看类以及类的个数
# -*- coding:utf-8 -*-
import os
import xml.etree.ElementTree as ET
import numpy as np
np.set_pr

该代码实现从XML文件中删除除'猫'和'狗'之外的所有类别的标签框,并将处理后的XML保存到新的1文件夹下。可以辅助检查不同类别的数量。
订阅专栏 解锁全文
1009

被折叠的 条评论
为什么被折叠?



