天天看点

iou画 yolov3_YOLOv3使用笔记——曲线可视化

转自: https://blog.csdn.net/cgt19910923/article/details/80783614

1.输出重定向

做训练的时候输出重定向得到训练日志文件

./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74 -gpus 0,1 2>1 | tee train_yolov3.log

2.解析日志文件

extract_log.py

# coding=utf-8

# 该文件用来提取训练log,去除不可解析的log后使log文件格式化,生成新的log文件供可视化工具绘图

import inspect

import os

import random

import sys

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('train_yolov3.log','train_log_loss.txt','images')

extract_log('train_yolov3.log','train_log_iou.txt','IOU')

解析loss行和iou行得到两个txt文件

3.loss曲线可视化

train_loss_visualization.py

根据train_log_loss.txt行数修改lines行

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

#%matplotlib inline

#lines =9873

lines=25100

result = pd.read_csv('train_log_loss.txt', skiprows=[x for x in range(lines)] ,error_bad_lines=False, names=['loss', 'avg', 'rate', 'seconds', 'images'])

result.head()

result['loss']=result['loss'].str.split(' ').str.get(1)

result['avg']=result['avg'].str.split(' ').str.get(1)

result['rate']=result['rate'].str.split(' ').str.get(1)

result['seconds']=result['seconds'].str.split(' ').str.get(1)

result['images']=result['images'].str.split(' ').str.get(1)

result.head()

result.tail()

#print(result.head())

# print(result.tail())import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

#%matplotlib inline

lines =9873

result = pd.read_csv('train_log_loss.txt', skiprows=[x for x in range(lines) if ((x<1000))] ,error_bad_lines=False, names=['loss', 'avg', 'rate', 'seconds', 'images'])

result.head()

result['loss']=result['loss'].str.split(' ').str.get(1)

result['avg']=result['avg'].str.split(' ').str.get(1)

result['rate']=result['rate'].str.split(' ').str.get(1)

result['seconds']=result['seconds'].str.split(' ').str.get(1)

result['images']=result['images'].str.split(' ').str.get(1)

result.head()

result.tail()

#print(result.head())

# print(result.tail())

# print(result.dtypes)

print(result['loss'])

print(result['avg'])

print(result['rate'])

print(result['seconds'])

print(result['images'])

result['loss']=pd.to_numeric(result['loss'])

result['avg']=pd.to_numeric(result['avg'])

result['rate']=pd.to_numeric(result['rate'])

result['seconds']=pd.to_numeric(result['seconds'])

result['images']=pd.to_numeric(result['images'])

result.dtypes

fig = plt.figure()

ax = fig.add_subplot(1, 1, 1)

ax.plot(result['avg'].values,label='avg_loss')

#ax.plot(result['loss'].values,label='loss')

ax.legend(loc='best')

ax.set_title('The loss curves')

ax.set_xlabel('batches')

fig.savefig('avg_loss')

#fig.savefig('loss')

# print(result.dtypes)

print(result['loss'])

print(result['avg'])

print(result['rate'])

print(result['seconds'])

print(result['images'])

result['loss']=pd.to_numeric(result['loss'])

result['avg']=pd.to_numeric(result['avg'])

result['rate']=pd.to_numeric(result['rate'])

result['seconds']=pd.to_numeric(result['seconds'])

result['images']=pd.to_numeric(result['images'])

result.dtypes

fig = plt.figure()

ax = fig.add_subplot(1, 1, 1)

ax.plot(result['avg'].values,label='avg_loss')

#ax.plot(result['loss'].values,label='loss')

ax.legend(loc='best')

ax.set_title('The loss curves')

ax.set_xlabel('batches')

fig.savefig('avg_loss')

#fig.savefig('loss')

iou画 yolov3_YOLOv3使用笔记——曲线可视化

4.iou曲线可视化

train_iou_visualization.py

根据train_log_iou.txt行数修改一下lines行,这个数值比较大。

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

#%matplotlib inline

lines =1994726

result = pd.read_csv('train_log_iou.txt', skiprows=[x for x in range(lines) if (x%39!=0|(x<1000))] ,error_bad_lines=False, names=['Region Avg IOU', 'Class', 'Obj', 'No Obj', 'Avg Recall','count'])

result.head()

result['Region Avg IOU']=result['Region Avg IOU'].str.split(': ').str.get(1)

result['Class']=result['Class'].str.split(': ').str.get(1)

result['Obj']=result['Obj'].str.split(': ').str.get(1)

result['No Obj']=result['No Obj'].str.split(': ').str.get(1)

result['Avg Recall']=result['Avg Recall'].str.split(': ').str.get(1)

result['count']=result['count'].str.split(': ').str.get(1)

result.head()

result.tail()

#print(result.head())

# print(result.tail())

# print(result.dtypes)

print(result['Region Avg IOU'])

result['Region Avg IOU']=pd.to_numeric(result['Region Avg IOU'])

result['Class']=pd.to_numeric(result['Class'])

result['Obj']=pd.to_numeric(result['Obj'])

result['No Obj']=pd.to_numeric(result['No Obj'])

result['Avg Recall']=pd.to_numeric(result['Avg Recall'])

result['count']=pd.to_numeric(result['count'])

result.dtypes

fig = plt.figure()

ax = fig.add_subplot(1, 1, 1)

ax.plot(result['Region Avg IOU'].values,label='Region Avg IOU')

#ax.plot(result['Class'].values,label='Class')

#ax.plot(result['Obj'].values,label='Obj')

#ax.plot(result['No Obj'].values,label='No Obj')

#ax.plot(result['Avg Recall'].values,label='Avg Recall')

#ax.plot(result['count'].values,label='count')

ax.legend(loc='best')

#ax.set_title('The Region Avg IOU curves')

ax.set_title('The Region Avg IOU curves')

ax.set_xlabel('batches')

#fig.savefig('Avg IOU')

fig.savefig('Region Avg IOU')

iou画 yolov3_YOLOv3使用笔记——曲线可视化

标签:loss,YOLOv3,log,笔记,train,可视化,result,str,import

来源: https://blog.csdn.net/duanyajun987/article/details/88425718