YOLO訓練數據繪製loss、IOU、Recall曲線

 

一、格式化log,用生成的新的txt文件供可視化工具繪圖,共生成兩個文件:train_log_loss.txt和train_log_iou.txt

# coding=utf-8
def extract_log(log_file,new_log_file,key_word):
    with open(log_file, 'r') as f:
      with open(new_log_file, 'w') as train_log:
  #f = open(log_file)
    #train_log = open(new_log_file, 'w')
        for line in f:
    # 去除多gpu的同步log
          if 'Syncing' in line:
            continue
    # 去除除零錯誤的log
          if 'nan' in line:
            continue
          if key_word in line:
            train_log.write(line)
    f.close()
    train_log.close()
 
extract_log('T:\\v2tiny.txt','T:\\train_log_loss.txt','images')
extract_log('T:\\v2tiny.txt','T:\\train_log_iou.txt','IOU')

 二、使用train_log_iou.txt文件計算平均IOU、召回率等

import matplotlib.pyplot as plt

 
f=open("T:\\train_log_iou.txt")

lines=[line.rstrip("\n") for line in f.readlines()]
ori=[]#原始數組
res=[]#求平均值後的數組
batchs=[]
add=0#相加和
num=0#統計個數
batch=0
subdivide =8#yolo中設置的subdivide
for line in lines:
    args=line.split(' ')
    ori.append(float(args[3][:-1]))#讀取agv iou值放入ori,如果計算Recall將3改爲13
sum=len(ori)
for i in range(sum):
    num=num+1
    add=add+ori[i]
    if (num>=subdivide):
        batch=batch+1
        avg=add/subdivide
        res.append(avg)
        batchs.append(batch)
        num=0
        agv=0
        add=0
fig = plt.figure()        
ax=fig.add_subplot(1, 1, 1)
ax.plot(batchs,res)
ax.set_title('The Region Avg IOU curves')
#ax.set_xlim(0, 18000,2000)
#ax.set_ylim(0, 1,0.2)
ax.set_xlabel('batch')
ax.set_ylabel('agv IOU')

三、使用 train_log_loss.txt繪製loss損失曲線

import matplotlib.pyplot as plt
#%matplotlib inline
 
f=open("T:\\train_log_loss.txt")

lines=[line.rstrip("\n") for line in f.readlines()]
ori=[]#原始數組
res=[]#求平均值後的數組
batchs=[]
add=0#相加和
num=0#統計個數
batch=0
subdivide =1#yolo中設置的subdivide
for line in lines:
    args=line.split(' ')
    ori.append(float(args[3][:-1]))#讀取agv iou值放入ori
sum=len(ori)
for i in range(sum):
    num=num+1
    add=add+ori[i]
    if (num>=subdivide):
        batch=batch+1
        avg=add/subdivide
        res.append(avg)
        batchs.append(batch*10)
        num=0
        agv=0
        add=0
fig = plt.figure()        
ax=fig.add_subplot(1, 1, 1)
ax.plot(batchs,res)
#ax.set_xlim(0, 18000,2000)
#ax.set_ylim(0, 1,0.2)
ax.set_title('The Region Avg IOU curves')
ax.set_xlabel('batch')
ax.set_ylabel('agv IOU')

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章