当前位置: 首页 > news >正文

YOLO训练results.csv文件可视化(原模型与改进模型对比可视化)

一、单独一个文件可视化(源码对应utils文件夹下的plots.py文件的plot_results类)

from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
def plot_results(file='runs/train/exp9/results.csv', dir=''):# Plot training results.csv. Usage: from utils.plots import *; plot_results('path/to/results.csv')save_dir = Path(file).parent if file else Path(dir)fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True)ax = ax.ravel()files = list(save_dir.glob(file))assert len(files), f'No results.csv files found in {save_dir.resolve()}, nothing to plot.'for fi, f in enumerate(files):try:data = pd.read_csv(f)s = [x.strip() for x in data.columns]x = data.values[:, 0]for i, j in enumerate([1, 2, 3, 4, 5, 8, 9, 10, 6, 7]):y = data.values[:, j]# y[y == 0] = np.nan  # don't show zero valuesax[i].plot(x, y, marker='.', label=f.stem, linewidth=2, markersize=8)ax[i].set_title(s[j], fontsize=12)# if j in [8, 9, 10]:  # share train and val loss y axes#     ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])except Exception as e:print(f'Warning: Plotting error for {f}: {e}')ax[1].legend()fig.savefig(save_dir / 'results.png', dpi=200)  #修改保存路径plt.close()if __name__ == '__main__':plot_results(file='results.csv')   #该python文件位于根目录下(此文件和传入文件在同一目录下),注意修改传入文件路径

单独把代码拿出来建立py文件,注意上传文件路径以及文件保存路径。

效果图展示:(results.png文件)

在这里插入图片描述
二、两个results.csv文件对比(经常用于原模型与改进模型训练效果对比):
这里用到了两个csv文件(results.csv(改进模型训练80轮)和results100.csv(原模型训练100轮))

from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
def plot_results(file='runs/train/exp9/results.csv', file2='runs/train/exp9/results100.csv' , dir=''):# Plot training results.csv. Usage: from utils.plots import *; plot_results('path/to/results.csv')save_dir = Path(file).parent if file else Path(dir)save_dir2 = Path(file2).parent if file2 else Path(dir)fig, ax = plt.subplots(2, 5, figsize=(12, 6), tight_layout=True)ax = ax.ravel()files = list(save_dir.glob(file))assert len(files), f'No results.csv files found in {save_dir.resolve()}, nothing to plot.'files2 = list(save_dir2.glob(file2))assert len(files2), f'No results.csv files found in {save_dir2.resolve()}, nothing to plot.'for fi, f in enumerate(files):try:data = pd.read_csv(f)s = [x.strip() for x in data.columns]x = data.values[:, 0]for i, j in enumerate([1, 2, 3, 4, 5, 8, 9, 10, 6, 7]):y = data.values[:, j]# y[y == 0] = np.nan  # don't show zero valuesax[i].plot(x, y, marker='.', label=f.stem, linewidth=2, markersize=8)ax[i].set_title(s[j], fontsize=12)# if j in [8, 9, 10]:  # share train and val loss y axes#     ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])except Exception as e:print(f'Warning: Plotting error for {f}: {e}')for fi, f in enumerate(files2):try:data = pd.read_csv(f)s = [x.strip() for x in data.columns]x = data.values[:, 0]for i, j in enumerate([1, 2, 3, 4, 5, 8, 9, 10, 6, 7]):y = data.values[:, j]# y[y == 0] = np.nan  # don't show zero valuesax[i].plot(x, y, marker='.', label=f.stem, linewidth=2, markersize=8)ax[i].set_title(s[j], fontsize=12)# if j in [8, 9, 10]:  # share train and val loss y axes#     ax[i].get_shared_y_axes().join(ax[i], ax[i - 5])except Exception as e:print(f'Warning: Plotting error for {f}: {e}')ax[1].legend()fig.savefig(save_dir / 'results_vs.png', dpi=200)  #修改保存路径plt.close()if __name__ == '__main__':plot_results(file='results.csv',file2='results100.csv')   #该python文件位于根目录下(此文件和传入文件在同一目录下),注意修改传入文件路径

效果图展示:(results_vs.png文件)

在这里插入图片描述
搬运自YOLO训练results.csv文件可视化(原模型与改进模型对比可视化)

http://www.lryc.cn/news/269538.html

相关文章:

  • uni-appcss语法
  • java在线票务系统(选座)Myeclipse开发mysql数据库web结构java编程计算机网页项目
  • Python 简易图形界面库easygui 对话框大全(续)
  • 电容器50ZLH56MEFC6.3X11
  • vscode 支持c,c++编译调试方法
  • MyBatis的缓存!!!!
  • ToB还是ToC?工业级与消费级AR眼镜都能干什么?
  • 设计模式-Java版本
  • 数据库中如何修改和删除字段
  • 在 Golang 应用程序中管理多个数据库
  • 理解开源协议GPL、MIT、BSD、Apache License
  • Talk | 北京大学博士生汪海洋:通向3D感知大模型的前置方案
  • 【C语言数组传参】规则详解
  • 【Linux】Ubuntu22.04版本下实现gcc版本的快速切换
  • 使用Node Exporter采集主机数据
  • Django 文件上传(十二)
  • k8s的陈述式资源管理
  • electron-builder 打包exe后白屏
  • mvvm,vue双向数据绑定的原理
  • 【Java中序列化的原理是什么(解析)】
  • 冠赢互娱基于 OpenKrusieGame 实现游戏云原生架构升级
  • Mybatis 动态 SQL - trim, where, set
  • 大模型系列:OpenAI使用技巧_使用OpenAI进行K-means聚类
  • 共享单车之数据分析
  • Spring的Bean你了解吗
  • MongoDB聚合:$merge 阶段(1)
  • 2. 云原生实战之kubesphere搭建
  • main参数传递、反汇编、汇编混合编程
  • 前后端分离nodejs+vue医院预约挂号系统6nrhh
  • 在pytorch中,读取GPU上张量的数值 (数据从GPU到CPU) 的几种常用方法