已封装成函数,直接在注释处修改成自己存放标签的路径, 数据集的类别数即可使用
from pathlib import Path
def box_count_yolo(path, num_classes):
lis = [0 for _ in range(num_classes)]
n = 0
for f in Path.iterdir(Path(path)):
with open(Path(f)) as file:
temp = file.read()
temp = temp.split()
for num in temp:
if len(str(num)) == 1:
lis[int(num)] += 1
print(lis)
n += 1
print(f"--------{n}个文件处理完成--------")
print(lis)
if __name__ == '__main__':
box_count_yolo("data/0708data/labels/test", 7) # 修改成自己存放标签的路径, 数据集的类别数
我的文件结构