一、格式化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')