TSRDA / ablations /04_error_diagnostics /plot_evidence.py
Dhruv1000's picture
Organize complete final models, all ablations, logs and checkpoints with visual guides (part 2)
aaa8065 verified
Raw History Blame Contribute Delete
1.71 kB
import sys,json
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]))
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from dataset import get_meta,train_patch_ids
p=Path(__file__).parent;d=json.loads((p/'plateau_diagnostics.json').read_text());test=json.loads(Path('analysis_oct05/per_class_audit.json').read_text())
plt.rcParams.update({'font.size':10,'axes.spines.top':False,'axes.spines.right':False})
fig,axs=plt.subplots(1,2,figsize=(13,5),layout='constrained')
seq=sorted(set(tuple(get_meta()[pid]['dates']) for pid in train_patch_ids()))
for k,days in enumerate(seq):axs[0].plot(np.arange(len(days)),days,label=f'Calendar {k+1}')
axs[0].axvline(20,color='grey',linestyle=':',alpha=.7)
axs[0].set(xlabel='Acquisition index supplied to the model',ylabel='Actual day offset in metadata',title='The same index can mean different seasonal dates')
axs[0].legend(loc='lower right',fontsize=9)
classes=[17,10,18,13,12,14,9];pos=np.arange(len(classes))
for label,key,color,offset in [('Validation','sam_val_iou','#2577ad',-.18),('Test','test_iou','#d88b33',.18)]:
values=[100*(d['per_class_fixed_validation'][c-1][key] if label=='Validation' else test[c-1][key]) for c in classes]
axs[1].barh(pos+offset,values,height=.34,label=label,color=color)
labels=[d['per_class_fixed_validation'][c-1]['name']+f" ({d['per_class_fixed_validation'][c-1]['train_unique_patches']} train patches)" for c in classes]
axs[1].set_yticks(pos,labels);axs[1].invert_yaxis();axs[1].set(xlim=(0,100),xlabel='Class IoU (%)',title='Rare-class evidence is geographically sparse');axs[1].legend()
fig.savefig(p/'plateau_evidence.png',dpi=180);plt.close(fig)