根据模型log文件画loss曲线
思想:使用Python的matplotlib
库来绘制loss曲线。首先需要解析log文件,提取出每个epoch对应的loss值,然后再进行绘制。
import re
import matplotlib.pyplot as plt
# 初始化数据列表
epochs = []
losses = []
# 读取log文件
with open('/log/TextPretrain.2024-06-18-1101.log', 'r') as file:
for line in file:
# 查找Epoch
epoch_match = re.search(r'Epoch:(\d+)', line)
if epoch_match:
epochs.append(int(epoch_match.group(1)))
# 查找Loss
loss_match = re.search(r'Loss:([\d\.]+)', line)
if loss_match:
losses.append(float(loss_match.group(1)))
# 绘制loss曲线
plt.figure(figsize=(10, 5))
plt.plot(epochs, losses, marker='o', linestyle='-', color='b')
plt.xlabel('Epoch')
plt.ylabel('Loss')
plt.title('Text Encoder Loss Curve')
plt.grid(True)
plt.show()
😃😃😃