import re
import seaborn as sns
import pandas as pd
import json
import matplotlib.pyplot as plt
with open('log.txt', 'r') as f:
data = f.readlines()
f.close()
data_list = list(map(lambda x: re.findall('训练(.?)次,loss:(.?)(\d{0,5}, \d{0,5}, (.*?))', x), data))
dict_data = str({i : data_list[i] for i in range(len(data_list))})
final_list = []
for i in range(len(data_list)):
final_list.append(list(data_list[i][0]))
df = pd.DataFrame(final_list, columns=['num','loss','correct'], dtype = float)
fig, axes_arr = plt.subplots(2, 1, figsize=(2, 5))
fig1 = sns.lineplot(x = 'num', y ='loss', data = df, ax = axes_arr[0], color = 'red')
axes_arr[0].legend(('loss',), loc = 2)
fig1.set_ylim(0, 0.3) # 限制y的值为[0,1]
axes_arr[0].grid()
sns.lineplot(x = 'num', y ='correct', data = df, ax = axes_arr[1], color = 'green')
axes_arr[1].legend(('correct',), loc = 2)
axes_arr[1].grid()
plt.show()