当前位置:   article > 正文

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

yolo csv文件怎么用

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

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

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

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


 二、两个results.csv文件对比(经常用于原模型与改进模型训练效果对比):

        这里用到了两个csv文件(results.csv(改进模型训练80轮)和results100.csv(原模型训练100轮))

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/129771?site
推荐阅读
相关标签
  

闽ICP备14008679号