Hello,
This is a bug on fastai’s side. Specifically, the plot_lr_find
function ignores the return_fig
argument and never returns a value.
Currently, this function is implemented as follows,
def plot_lr_find(self:Recorder, skip_end=5, return_fig=True, suggestions=None, nms=None, **kwargs):
"Plot the result of an LR Finder test (won't work if you didn't do `learn.lr_find()` before)"
lrs = self.lrs if skip_end==0 else self.lrs [:-skip_end]
losses = self.losses if skip_end==0 else self.losses[:-skip_end]
fig, ax = plt.subplots(1,1)
ax.plot(lrs, losses)
ax.set_ylabel("Loss")
ax.set_xlabel("Learning Rate")
ax.set_xscale('log')
if suggestions:
colors = plt.rcParams['axes.prop_cycle'].by_key()['color'][1:]
for (val, idx), nm, color in zip(suggestions, nms, colors):
ax.plot(val, idx, 'o', label=nm, c=color)
ax.legend(loc='best')
However, it should be,
def plot_lr_find(self:Recorder, skip_end=5, return_fig=True, suggestions=None, nms=None, **kwargs):
"Plot the result of an LR Finder test (won't work if you didn't do `learn.lr_find()` before)"
lrs = self.lrs if skip_end==0 else self.lrs [:-skip_end]
losses = self.losses if skip_end==0 else self.losses[:-skip_end]
fig, ax = plt.subplots(1,1)
ax.plot(lrs, losses)
ax.set_ylabel("Loss")
ax.set_xlabel("Learning Rate")
ax.set_xscale('log')
if suggestions:
colors = plt.rcParams['axes.prop_cycle'].by_key()['color'][1:]
for (val, idx), nm, color in zip(suggestions, nms, colors):
ax.plot(val, idx, 'o', label=nm, c=color)
ax.legend(loc='best')
return fig if return_fig else None
The lines below would now yield the desired results. Alternatively, you could monkey-patch plot_lr_find
or modify fastai’s source code to save you from future hassle.
fig = plot_lr_find(learner.recorder, return_fig=True)
fig.savefig('lrfind.png')
Please let me know if this is helpful.