这部分先贴出分析类别的代码,后续会继续添加分析bbox的shape等的信息的代码
import os
import xml.etree.ElementTree as ET
from collections import Counter
import numpy as np
ann_path = '/训练集/Annotations/'
ann_list = os.listdir(ann_path)
img_num = len(ann_list)
cat = []
for xml in ann_list:
xml_path = ann_path + xml
tree = ET.parse(xml_path)
root = tree.getroot()
for object in root.findall('object'):
object_name = object.find('name').text
cat.append(object_name)
data_cls = dict(Counter(cat))
for key in data_cls.keys():
print(key,':', data_cls[key])
print("图片总量:", img_num)