yolo训练之训练结果评估环节

在yolo中,怎么知道自己已经训练的怎么样了呢?自然是希望把训练过程中的loss等数据可视化一下,这篇文章中,我们主要就介绍一下这些。

1.记录终端信息到文件

首先在训练开始的时候需要把终端信息记录到文件,我这里使用的命令是| tee train_log.txt ,可参考:Linux中记录终端(Terminal)输出到文本文件 。我们会得到这样一个文本文件:
这里写图片描述

2. python数据处理

下面我们就可以用python对其进行处理了,这里我写了两个jupyter notebook,第一个可视化了loss,第二个可视化了iou。

#### **A.可视化loss**
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
result = pd.read_csv('trainlog.txt', skiprows=[x for x in range(60000) if x%10!=9] ,error_bad_lines=False, names=['loss', 'avg', 'rate', 'seconds', 'images'])
result.head()
lossavgratesecondsimages
01: 121.201286121.201286 avg0.000500 rate5.607964 seconds64 images
12: 116.259315120.707092 avg0.000500 rate5.027367 seconds128 images
23: 92.172997117.853683 avg0.000500 rate5.162279 seconds192 images
34: 85.307167114.599030 avg0.000500 rate4.845596 seconds256 images
45: 81.885292111.327652 avg0.000500 rate5.068791 seconds320 images
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()
lossavgratesecondsimages
50060.9037840.9238440.0100004.661594320448
50070.8568210.9171420.0100004.695950320512
50080.9177660.9172040.0100004.740102320576
50090.8665800.9121420.0100004.713165320640
50101.0710780.9280350.0100004.728881320704
# print(result.head())
# print(result.tail())
# print(result.dtypes)
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
loss float64 avg float64 rate float64 seconds float64 images int64 dtype: object
result['loss'].plot()
p=result['avg'].plot()
![这里写图片描述](https://img-blog.csdn.net/20161229091306874?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTk5OTk5OTk5OTk5OWQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 图
result['avg'].values
array([ 121.201286, 120.707092, 117.853683, …, 0.917204, 0.912142, 0.928035])
fig = plt.figure();
ax = fig.add_subplot(1, 1, 1)
ax.plot(result['avg'].values,label='avg_loss')
ax.legend(loc='best')
ax.set_title('The loss curves')
ax.set_xlabel('batches')
fig.savefig('avg_loss')
![这里写图片描述](https://img-blog.csdn.net/20161229091337399?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTk5OTk5OTk5OTk5OWQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast) 图 #### **B.可视化IOU**
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
result = pd.read_csv('trainlog.txt', skiprows=[x for x in range(500000) if x%10==9 or x%10==0] ,error_bad_lines=False, names=['Detection Avg IOU', 'Pos Cat', 'All Cat', 'Pos Obj', 'Any Obj', 'count'])
result.head()
Detection Avg IOUPos CatAll CatPos ObjAny Objcount
0Detection Avg IOU: 0.061472Pos Cat: -0.054766All Cat: 0.160247Pos Obj: -0.081178Any Obj: -0.016451count: 16
1Detection Avg IOU: 0.083749Pos Cat: 0.272016All Cat: 0.223963Pos Obj: 0.130788Any Obj: -0.018666count: 14
2Detection Avg IOU: 0.105311Pos Cat: 0.178397All Cat: 0.069925Pos Obj: -0.062407Any Obj: -0.016685count: 17
3Detection Avg IOU: 0.056007Pos Cat: 0.142428All Cat: 0.043840Pos Obj: -0.197250Any Obj: -0.051494count: 15
4Detection Avg IOU: 0.085293Pos Cat: 0.108593All Cat: 0.033600Pos Obj: 0.020100Any Obj: -0.012297count: 15
result['Detection Avg IOU']=result['Detection Avg IOU'].str.split(': ').str.get(1)
result['Pos Cat']=result['Pos Cat'].str.split(': ').str.get(1)
result['All Cat']=result['All Cat'].str.split(': ').str.get(1)
result['Pos Obj']=result['Pos Obj'].str.split(': ').str.get(1)
result['Any Obj']=result['Any Obj'].str.split(': ').str.get(1)
result['count']=result['count'].str.split(': ').str.get(1)
result.head()
Detection Avg IOUPos CatAll CatPos ObjAny Objcount
00.061472-0.0547660.160247-0.081178-0.01645116
10.0837490.2720160.2239630.130788-0.01866614
20.1053110.1783970.069925-0.062407-0.01668517
30.0560070.1424280.043840-0.197250-0.05149415
40.0852930.1085930.0336000.020100-0.01229715
result['Detection Avg IOU']=pd.to_numeric(result['Detection Avg IOU'])
result['Pos Cat']=pd.to_numeric(result['Pos Cat'])
result['All Cat']=pd.to_numeric(result['All Cat'])
result['Pos Obj']=pd.to_numeric(result['Pos Obj'])
result['Any Obj']=pd.to_numeric(result['Any Obj'])
result['count']=pd.to_numeric(result['count'])
result.dtypes
Detection Avg IOU    float64
Pos Cat              float64
All Cat              float64
Pos Obj              float64
Any Obj              float64
count                  int64
dtype: object
result['Detection Avg IOU'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f4cdc6691d0>

这里写图片描述

result['Pos Cat'].plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7f4cdc66c390>

这里写图片描述

3. 看看结果至少还是符合趋势的,哈哈

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值