赞
踩
每个csv文件内容如下
##### 代码
# 绘制目标检测损失对比曲线 import matplotlib import pandas as pd import warnings import matplotlib.pyplot as plt warnings.filterwarnings("ignore", category=matplotlib.MatplotlibDeprecationWarning) # 进行绘图操作 net2 = pd.read_csv('/Volumes/LaCie/卷积神经网络实现minst数据集分类/minst_demo/edata2/logs2-train_loss/logs2-net2-train_loss.csv', usecols=['Step', 'Value']) plt.plot(net2.Step, net2.Value, lw=1.0, label='net2', color='blue') net4 = pd.read_csv('/Volumes/LaCie/卷积神经网络实现minst数据集分类/minst_demo/edata2/logs2-train_loss/logs2-net4-train_loss.csv', usecols=['Step', 'Value']) plt.plot(net4.Step, net4.Value, lw=1.0, label='net4', color='red', linestyle='dashdot') # 使用曲线插值 net5 = pd.read_csv('/Volumes/LaCie/卷积神经网络实现minst数据集分类/minst_demo/edata2/logs2-train_loss/logs2-net5-train_loss.csv', usecols=['Step', 'Value']) plt.plot(net5.Step, net5.Value, lw=1.0, label='net5', color='black', linestyle='dashdot') # 使用曲线插值 plt.xlabel('Epoch') plt.ylabel('loss') plt.legend(loc=0) plt.show()
效果
写到这里突然发现有种更简单的方法,后面有时间在补吧!
放个清楚一点的就是这样的
注意,有的模型训练的时候使用了早停机制,所以两个需要对比的csv文件的epoch是不一样的,如果你需要实现以最小的那个epoch为准使用下面这段代码
import pandas as pd import matplotlib.pyplot as plt # 读取两个CSV文件 data1 = pd.read_csv('train_data/train23_1/results.csv') data2 = pd.read_csv('train_data/train2_1/results.csv') # 去除列名前后的空格 data1.columns = data1.columns.str.strip() data2.columns = data2.columns.str.strip() # 提取'epoch'和'metrics/recall(B)'列的数据 epoch1 = data1['epoch'] recall1 = data1['metrics/recall(B)'] epoch2 = data2['epoch'] recall2 = data2['metrics/recall(B)'] # 找到两个数据集中的最大epoch值 min_epoch1 = max(epoch1) print(min_epoch1) min_epoch2 = max(epoch2) print(min_epoch2) # 取两个数据集中最大epoch值的最小值,以确定共同的epoch范围 min_common_epoch = min(min_epoch1, min_epoch2) # 仅保留小于最小共同epoch值的数据点 epoch1 = epoch1[epoch1 < min_common_epoch] recall1 = recall1[:len(epoch1)] epoch2 = epoch2[epoch2 < min_common_epoch] recall2 = recall2[:len(epoch2)] # 绘制曲线 plt.plot(epoch1, recall1, lw=1.0, label='net1', color='blue') plt.plot(epoch2, recall2, lw=1.5, label='net2', color='red') plt.xlabel('Epoch') plt.ylabel('Recall') plt.legend(loc=0) plt.show()
效果如下:
当然,如果你想体现所有的epoch,那就更简单了。下面这段代码请食用:
import pandas as pd import matplotlib.pyplot as plt # 读取CSV文件,不仅仅包括'epoch'和'metrics/recall(B)'列 data1 = pd.read_csv('train_data/train23_1/results.csv') # 去除列名前后的空格,并提取'epoch'和'metrics/recall(B)'列的数据 data1.columns = data1.columns.str.strip() epoch1 = data1['epoch'] recall1 = data1['metrics/recall(B)'] plt.plot(epoch1, recall1, lw=1.0, label='YOLOv8', color='blue') # 类似地处理第二个数据集 data2 = pd.read_csv('train_data/train2_1/results.csv') data2.columns = data2.columns.str.strip() epoch2 = data2['epoch'] recall2 = data2['metrics/recall(B)'] plt.plot(epoch2, recall2, lw=1.5, label='Diamond-YOLO', color='red') # 使用曲线插值 plt.xlabel('Epoch') plt.ylabel('Recall') plt.legend(loc=0) plt.show()
效果如下:
持续更新中…
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。