import numpy as np
import matplotlib.pyplot as plt
with open('C:\\Users\\dell\\Desktop\\shujuji.txt', 'w+') as fd:
with open('C:\\Users\\dell\\Desktop\\accuracy.txt', 'r') as fa:
with open('C:\\Users\\dell\\Desktop\\top1.txt', 'r') as fb:
with open('C:\\Users\\dell\\Desktop\\top5.txt', 'r') as fc:
i=0
for line in fa:
i=i+1
linea=line.strip('\r\n')
lineb=fb.readline()
linec=fc.readline()
fd.write(str(i)+" "+linea+" "+lineb.strip('\r\n')+" "+linec.strip('\r\n'))
fd.write("\n")
x = []
y1 = []
y2 = []
y3 = []
with open("C:\\Users\\dell\\Desktop\\shujuji.txt","r")as fd:
for line in fd:
line = line.strip('\n')
line = line.split(' ')
x.append(float(line[0]))
y1.append(float(line[1]))
y2.append(float(line[2]))
y3.append(float(line[3]))
plt.plot(x,y1,c='royalblue', label="current")
plt.plot(x,y2,c='coral',label="top1")
plt.plot(x,y3,c='black',label="top5") # 画线
plt.scatter(x,y1,c='royalblue')
plt.scatter(x,y2,c='coral')
plt.scatter(x,y3,c='black') # 画点
plt.legend(loc='best',frameon=False) # 图例边框
plt.xticks(range(0, 21, 1))
plt.yticks(range(0, 110,10))# x,y轴刻度
plt.xlabel("Epoch", fontdict={'size': 16})
plt.ylabel("Percentage%", fontdict={'size': 16})
plt.title("评价标准图", fontdict={'size': 20})
plt.show()
3.print()函数
该代码读取多个文件中的数据,将数据整合并写入新的文件中。然后,它从新文件中提取数据,用于创建一个折线图和散点图,显示当前、top1和top5的精度随训练轮数(Epoch)的变化情况。图表清晰地展示了各个指标在不同Epoch的表现。
摘要由CSDN通过智能技术生成