020基于安全帽检测训练集编写Excel

一、

需要把YOLOv3训练的结果的各个值记录到Excel中,实现python脚本如下:

import re,xlwt
f = open("epoch.txt")
lines = f.readlines()
#新建工作簿
workbook = xlwt.Workbook(encoding='utf-8')
#新建sheet
sheet1 = workbook.add_sheet("测试表格")
#第1行第1列数据
sheet1.write(0,0,"loss")
#第1行第2列数据
sheet1.write(0,1,"yolo_layer_1_loss")
sheet1.write(0,2,"yolo_layer_2_loss")
sheet1.write(0,3,"yolo_layer_3_loss")
sheet1.write(0,4,"val_loss")
sheet1.write(0,5,"val_yolo_layer_1_loss")
sheet1.write(0,6,"val_yolo_layer_2_loss")
sheet1.write(0,7,"val_yolo_layer_3_loss")
lineNumber = 1
for line in lines:
    # print(line)
    values = re.findall(r"loss:\s+(\d+\.\d+)\s+\-\s+yolo_layer_1_loss: (\d+\.\d+)\s+\-\s+yolo_layer_2_loss: (\d+\.\d+)\s+\-\s+yolo_layer_3_loss: (\d+\.\d+)\s+\-\s+val_loss: (\d+\.\d+)\s+\-\s+val_yolo_layer_1_loss: (\d+\.\d+)\s+\-\s+val_yolo_layer_2_loss: (\d+\.\d+)\s+\-\s+val_yolo_layer_3_loss: (\d+\.\d+)",line)
    if len(values) >= 1:
        print(values)
        sheet1.write(lineNumber, 0, values[0][0])
        sheet1.write(lineNumber, 1, values[0][1])
        sheet1.write(lineNumber, 2, values[0][2])
        sheet1.write(lineNumber, 3, values[0][3])
        sheet1.write(lineNumber, 4, values[0][4])
        sheet1.write(lineNumber, 5, values[0][5])
        sheet1.write(lineNumber, 6, values[0][6])
        sheet1.write(lineNumber, 7, values[0][7])
        lineNumber = lineNumber+1
f.close()
workbook.save("test.xls")

效果如下:

020基于安全帽检测训练集编写Excel

 

上一篇:YOLO V5安装与验证


下一篇:图片标注软件labelImg使用指南