import matplotlib.pyplot as plt import numpy as np line = [] with open(r"./loss.log", encoding='utf-8') as f: # 从log文件中读出数据 for line1 in f: line.append(line1) datalist = [] for item in line: strl = item.split() datalist.append(strl) train_loss=[] test_loss=[] for item in datalist: if len(item)>9: if item[7] == 'Train': train_loss.append(item[10]) # 7为Train字段所在的位置,10为Train loss值所在位置 elif item[9] == 'test': test_loss.append(item[11]) # 同上 plt.figure() plt.subplot(121) plt.plot(range(len(train_loss)), np.float32(train_loss)) plt.subplot(122) plt.plot(range(len(test_loss)), np.float32(test_loss)) plt.show()
从txt或者log文件中提取特定字符所在行,可用于loss曲线绘制
最新推荐文章于 2023-02-07 11:24:52 发布