赞
踩
- import os
- import csv
-
- # 文件夹路径
- folder_path = r"E:\yolov5-master\runs\train"
-
- # 创建结果csv文件并写入表头
- result_file = "epresult.csv"
- with open(result_file, mode='w', newline='') as file:
- writer = csv.writer(file)
- writer.writerow(['Folder Name', 'Line Count', 'metrics/mAP_0.5', 'metrics/mAP_0.5:0.95'])
-
- # 遍历文件夹
- for folder_name in os.listdir(folder_path):
- folder_dir = os.path.join(folder_path, folder_name)
-
- # 寻找.csv文件
- for file_name in os.listdir(folder_dir):
- if file_name.endswith(".csv"):
- csv_file = os.path.join(folder_dir, file_name)
-
- # 打开并读取CSV文件
- with open(csv_file, mode='r') as csv_data:
- csv_reader = csv.reader(csv_data)
- data = list(csv_reader)
-
- # 获取行数
- line_count = len(data) - 1
-
- # 提取指定列的最后一行数据
- mAP_0_5 = data[-1][data[0].index(' metrics/mAP_0.5')]
- mAP_0_5_0_95 = data[-1][data[0].index('metrics/mAP_0.5:0.95')]
-
- # 将提取的数据写入结果csv文件
- writer.writerow([folder_name, line_count, mAP_0_5, mAP_0_5_0_95])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。