import os
# 标签文件夹路径
annotation_folder = "D:/PycharmProjects/yolov5-master/bdd100knightyolo/labels/val"
# 统计各类别标签数量的字典
label_counts = {}
# 获取标签文件夹中所有标签文件的路径
annotation_files = os.listdir(annotation_folder)
# 遍历每个标签文件
for annotation_file in annotation_files:
# 标签文件路径
annotation_path = os.path.join(annotation_folder, annotation_file)
# 读取标签数据
with open(annotation_path, "r") as file:
annotations = file.readlines()
# 统计每个标签出现的次数
for annotation in annotations:
label = annotation.split()[0]
if label in label_counts:
label_counts[label] += 1
else:
label_counts[label] = 1
# 打印各类别标签数量
for label, count in label_counts.items():
print(f"{label}: {count}")
(七)每个类别计数,基于yolo格式标签
于 2023-10-07 18:21:23 首次发布