This commit is contained in:
huangtao
2022-07-01 14:19:10 +08:00
parent a857768c9e
commit 4bb117c407
7 changed files with 245 additions and 15 deletions

30
label_num.py Normal file
View File

@ -0,0 +1,30 @@
### 计算xml中每个类别标签的数量 ###
import os
import shutil
import xml.etree.ElementTree as ET
def caculate_label_numble(file_path):
label_numble_info = {}
for file in os.listdir(file_path):
if file.endswith(".xml"):
xml_path = os.path.join(file_path, file)
tree = ET.parse(xml_path)
root = tree.getroot()
for element in root.findall('object'):
for element1 in element.findall('name'):
if element1.text not in label_numble_info:
# if element1.text=="6935284412918":#查看异常分类对应的xml
# print(file)
label_numble_info[element1.text] = 1
else:
label_numble_info[element1.text] += 1
return label_numble_info
if __name__=="__main__":
file_path = "paper_data/Annotations"
label_numble_info = caculate_label_numble(file_path)
for key, value in label_numble_info.items():
print('{}:{}'.format(key, value))