YOLOX-绘制五种loss曲线

import matplotlib.pyplot as plt
import os
import numpy as np

fi_1 = open('YOLOX_outputs/yolox_voc_m/train_log.txt','r',encoding='utf-8')  #1、读取路径,改为自己的路径
iters_num = int('271740')  #2、自己估计下坐标轴x,这里是总迭代次数

lines = fi_1.readlines()

total_loss = []
iou_loss = []
l1_loss = []
conf_loss = []
cls_loss = []
for line in lines:
    if 'total_loss' in line:
        print(line)
        line0 = line.split('total_loss: ')[-1].split(', iou_loss:')[0]
        line1 = line.split('iou_loss: ')[-1].split(', l1_loss:')[0]
        line2 = line.split('l1_loss: ')[-1].split(', conf_loss:')[0]
        line3 = line.split('conf_loss: ')[-1].split(', cls_loss:')[0]
        line4 = line.split('cls_loss: ')[-1].split(', lr:')[0]
        total_loss.append(float(line0))
        iou_loss.append(float(line1))
        l1_loss.append(float(line2))
        conf_loss.append(float(line3))
        cls_loss.append(float(line4))
        print('-----------',line0,line1,line2,line3,line4)
        #break
print(len(total_loss))
# plt.style.use('ggplot')
plt.rc('font', family='Times New Roman', size=13)  # 全局中英文为字体“罗马字体”
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.figure(0,figsize=(10,8))
x = np.arange(0, iters_num, 10)  ################################ 自己估计下坐标轴x,这里10是源代码默认iter=10输出一次loss
plt.subplot(2,3,1)
plt.plot(x, total_loss, color= 'blue',label="Total Loss")
plt.xlabel("Steps")
plt.ylabel("Loss")
plt.grid(True)
plt.legend(loc="upper right",fontsize='xx-small')
plt.subplot(2,3,2)
plt.plot(x, iou_loss, color= 'red',label="iou Loss")
plt.xlabel("Steps")
plt.ylabel("Loss")
plt.grid(True)
plt.legend(loc="upper right",fontsize='xx-small')
plt.subplot(2,3,3)
plt.plot(x, l1_loss, color= 'green',label="l1 Loss")
plt.xlabel("Steps")
plt.ylabel("Loss")
plt.grid(True)
plt.legend(loc="upper right",fontsize='xx-small')
plt.subplot(2,3,4)
plt.plot(x, conf_loss, color= 'darkorange',label="conf Loss")
plt.xlabel("Steps")
plt.ylabel("Loss")
plt.grid(True)
plt.legend(loc="upper right",fontsize='xx-small')
plt.subplot(2,3,5)
plt.plot(x, cls_loss, color= 'indigo',label="cls Loss")
plt.xlabel("Steps")
plt.ylabel("Loss")
plt.grid(True)
plt.legend(loc="upper right",fontsize='xx-small')
plt.annotate("Loss", (-2,10), xycoords='data',xytext=(-2,10),fontsize=15)
plt.savefig('losses.png',dpi=600,bbox_inches='tight')
plt.show()

 

  • 12
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值