I was exploring the idea of using pandas styling to highlight the best results for the metrics in the metrics table when you train. I did a quick custom callback to change the default table.
For example using background gradients to show visually the best metrics your neural network got during training. Not sure about the styling, but I include the code if you want to customize it for your own projects:
import ipywidgets as widgets
from IPython.display import display, HTML
from fastai2.callback.all import *
import pandas as pd
from functools import partial
def highlight(s, usemax=True):
if usemax:
is_max = s == s.max()
else:
is_max = s == s.min()
return ['text-decoration: underline;' if v else '' for v in is_max]
class ColorfulProgressCallback(ProgressCallback):
def __init__(self):
super()
def begin_fit(self):
super().begin_fit()
if(hasattr(self, 'out')): delattr(self, 'out')
for i, cb in enumerate(self.learn.cbs):
if type(cb) == ProgressCallback:
self.learn.cbs[i] = self
def after_fit(self):
super().after_fit()
if(hasattr(self, 'all_log')): delattr(self, 'all_log')
def _write_stats(self, log):
if(not hasattr(self, 'all_log')):
self.all_log = pd.DataFrame([], columns=log)
return
self.all_log.loc[len(self.all_log)] = [l if isinstance(l, float) else str(l) for l in log]
for c in self.all_log.columns[1:-1]:
self.all_log[c] = self.all_log[c].astype(float)
s = self.all_log.style
for c in self.all_log.columns[1:-1]:
isR2 = 'R2' in c
low = .8 if isR2 else .2
high = .2 if isR2 else .8
s = s.background_gradient(cmap=f'viridis{"_r" if not isR2 else ""}', subset=c, low=low, high=high)
s.apply(partial(highlight, usemax=isR2), subset=[c])
s = s.hide_index()
if(hasattr(self, 'out')):
self.out.update(s)
else:
self.out = display(s, display_id=True)
Then you can use it like so:
learner.fit_one_cycle(10, 1e-3, cbs=[ColorfulProgressCallback()])