This article refers to how to use the data of Tensorboard, and use the plot() function by yourself to draw multiple loss curves in the same picture. The original code does not convert the read data to float type
deep learning training. Acc, val_acc, loss when using Tensorboard , Val_loss is not drawn on a graph, we can download the Tensorboard data and use the matplotlib module to draw separately.
specific method
1. Start Tensorboard and enter the interface
logs is your path
tensorboard --logdir logs
After successful startup, copy the path to your browser to open the Tensorboard interface
2. Download and save Tensorboard data
1. Select Show data download links in the upper left corner
2. Select the csv format of the download file in the lower right corner, if the download suffix is .txt, change it to .csv
Four data after successful download
Three, data file preprocessing
Delete the Wall time, Step, Value in the top line of the .csv file
Fourth, write the plot() function painting program
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from matplotlib.font_manager import FontProperties
import csv
'''读取csv文件'''
def readcsv(files):
csvfile = open(files, 'r')
plots = csv.reader(csvfile, delimiter=',')
x = []
y = []
#读取csv文件中2,3列的数据,且转化为float类型
for row in plots:
y.append(float(row[2]))
x.append(float(row[1]))
return x ,y
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'
plt.figure()
#读取四个文件
x2,y2=readcsv("run_.-tag-loss.csv")
plt.plot(x2, y2, color='red', label='loss')
x,y=readcsv("run_.-tag-val_loss.csv")
plt.plot(x, y, 'g',label='val_loss')
x1,y1=readcsv("run_.-tag-val_acc.csv")
plt.plot(x1, y1, color='black',label='val_acc')
x4,y4=readcsv("run_.-tag-acc.csv")
plt.plot(x4, y4, color='blue',label='acc')
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
#ylim和xlim的最大最小值根据csv文件的极大极小值决定
plt.ylim(0,2)
plt.xlim(0, 50)
plt.xlabel('Steps',fontsize=20)
plt.ylabel('Score',fontsize=20)
plt.legend(fontsize=16)
plt.show()
The painting is a bit ugly, you can beautify it yourself