Sometimes I want to train a bunch of models and save metrics quietly. Is there an option for suppressing the output of Learner.fit or Learner.fit_one_cycle?
You can use learn.recorder.silent = True
in any Callback to make this happen.
Fantastic, thanks.
@ericricky do you have a snippet that does this? When I try to set that value, it has no effect. Do I need to roll it inside a callback?
@bfarzin Yeah, you need to roll it inside a callback. Here’s a snippet:
@dataclass
class SilenceRecorder(Callback):
learn:Learner
def __post_init__(self):
self.learn.recorder.silent = True
Then define a learner like
l = Learner(..., callback_fns=[SilenceRecorder])
I just tried that, and I still get the bar updates but the final output with losses and times is suppressed. Is that what you expected?
Yeah, that’s what I get too. It’s good enough for my purposes now, but I was going to look into suppressing the bar and time output later. I think it should be an option for Learner.fit
so you can selectively show/hide output without modifying the learner’s callback_fns after creation.
Great. I wanted to be sure I was not missing something here. I have a context manager that you can use which will allow this on-the-fly. Looks like this (but I did not want to introduce complexity if there was a simple solution!)
import fastai
import fastprogress
class progress_disabled():
''' Context manager to disable the progress update bar and Recorder print'''
def __init__(self,learn:Learner):
self.learn = learn
def __enter__(self):
fastprogress.fastprogress.NO_BAR = True
fastai.basic_train.master_bar, fastai.basic_train.progress_bar = fastprogress.force_console_behavior()
self.learn.callback_fns[0] = partial(Recorder,add_time=True,silent=True) #silence recorder
return self.learn
def __exit__(self,type,value,traceback):
fastai.basic_train.master_bar, fastai.basic_train.progress_bar = master_bar,progress_bar
self.learn.callback_fns[0] = partial(Recorder,add_time=True)
Usage:
with progress_disabled(learn) as learn:
learn.fit(1)
I need to make a PR to check it in. I had the idea a while ago, but got sidetracked. I will get a PR out now on this.
Awesome, will definitely use this!
This will be part of the next release. You can get it by pulling the latest Github repo if you really want to try it out sooner!