C/C++教程

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

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!