1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| import matplotlib import matplotlib.pyplot as plt matplotlib.rc("font",family='SimHei') plt.plot([1,2,3], [100,500,300]) plt.title('matplotlib中文字体测试', fontsize=25) plt.xlabel('X轴', fontsize=15) plt.ylabel('Y轴', fontsize=15) plt.show() import pandas as pd
log_path = './work_dirs/ZihaoDataset-PSPNet/20230818_210528/vis_data/scalars.json' with open(log_path, "r") as f: json_list = f.readlines() len(json_list) eval(json_list[4])
for each in json_list[:-1]: new_row = pd.DataFrame([eval(each)]) if 'aAcc' in each: df_test = pd.concat([df_test, new_row], ignore_index=True) else: df_train = pd.concat([df_train, new_row], ignore_index=True) df_train df_test df_train.to_csv('图表/训练日志-训练集.csv', index=False) df_test.to_csv('图表/训练日志-测试集.csv', index=False) from matplotlib import colors as mcolors import random random.seed(124) colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan', 'black', 'indianred', 'brown', 'firebrick', 'maroon', 'darkred', 'red', 'sienna', 'chocolate', 'yellow', 'olivedrab', 'yellowgreen', 'darkolivegreen', 'forestgreen', 'limegreen', 'darkgreen', 'green', 'lime', 'seagreen', 'mediumseagreen', 'darkslategray', 'darkslategrey', 'teal', 'darkcyan', 'dodgerblue', 'navy', 'darkblue', 'mediumblue', 'blue', 'slateblue', 'darkslateblue', 'mediumslateblue', 'mediumpurple', 'rebeccapurple', 'blueviolet', 'indigo', 'darkorchid', 'darkviolet', 'mediumorchid', 'purple', 'darkmagenta', 'fuchsia', 'magenta', 'orchid', 'mediumvioletred', 'deeppink', 'hotpink'] markers = [".",",","o","v","^","<",">","1","2","3","4","8","s","p","P","*","h","H","+","x","X","D","d","|","_",0,1,2,3,4,5,6,7,8,9,10,11] linestyle = ['--', '-.', '-'] def get_line_arg(): ''' 随机产生一种绘图线型 ''' line_arg = {} line_arg['color'] = random.choice(colors) line_arg['linestyle'] = random.choice(linestyle) line_arg['linewidth'] = random.randint(1, 4) return line_arg metrics = ['loss', 'decode.loss_ce', 'aux.loss_ce'] plt.figure(figsize=(16, 8)) x = df_train['step'] for y in metrics: try: plt.plot(x, df_train[y], label=y, **get_line_arg()) except: pass plt.tick_params(labelsize=20) plt.xlabel('step', fontsize=20) plt.ylabel('Loss', fontsize=20) plt.title('训练集损失函数', fontsize=25) plt.legend(fontsize=20) plt.savefig('图表/训练集损失函数.pdf', dpi=120, bbox_inches='tight') plt.show() metrics = ['decode.acc_seg', 'aux.acc_seg'] plt.figure(figsize=(16, 8)) x = df_train['step'] for y in metrics: try: plt.plot(x, df_train[y], label=y, **get_line_arg()) except: pass plt.tick_params(labelsize=20) plt.xlabel('step', fontsize=20) plt.ylabel('Metrics', fontsize=20) plt.title('训练集准确率', fontsize=25) plt.legend(fontsize=20) plt.savefig('图表/训练集准确率.pdf', dpi=120, bbox_inches='tight') plt.show() df_test.columns metrics = ['aAcc', 'mIoU', 'mAcc', 'mDice', 'mFscore', 'mPrecision', 'mRecall'] plt.figure(figsize=(16, 8) x = df_test['step'] for y in metrics: try: plt.plot(x, df_test[y], label=y, **get_line_arg()) except: pass plt.tick_params(labelsize=20) plt.ylim([0, 100]) plt.xlabel('step', fontsize=20) plt.ylabel('Metrics', fontsize=20) plt.title('测试集评估指标', fontsize=25) plt.legend(fontsize=20) plt.savefig('图表/测试集分类评估指标.pdf', dpi=120, bbox_inches='tight') plt.show()
|