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')

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想想叫啥名

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值