1.3
This commit is contained in:
30
label_num.py
Normal file
30
label_num.py
Normal 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))
|
Reference in New Issue
Block a user