Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jantic
GitHub Repository: jantic/deoldify
Path: blob/master/fastai/utils/mod_display.py
781 views
1
" Utils for modifying what is displayed in notebooks and command line"
2
import fastai
3
import fastprogress
4
5
from ..basic_train import *
6
from ..core import *
7
8
__all__ = ['progress_disabled_ctx']
9
10
class progress_disabled_ctx():
11
"Context manager to disable the progress update bar and Recorder print."
12
def __init__(self,learn:Learner):
13
self.learn = learn
14
15
def __enter__(self):
16
#silence progress bar
17
fastprogress.fastprogress.NO_BAR = True
18
fastai.basic_train.master_bar,fastai.basic_train.progress_bar = fastprogress.force_console_behavior()
19
self.orig_callback_fns = copy(self.learn.callback_fns)
20
rec_name = [x for x in self.learn.callback_fns if hasattr(x, 'func') and x.func == Recorder]
21
if len(rec_name):
22
rec_idx = self.learn.callback_fns.index(rec_name[0])
23
self.learn.callback_fns[rec_idx] = partial(Recorder, add_time=True, silent=True) #silence recorder
24
return self.learn
25
26
def __exit__(self, *args):
27
fastai.basic_train.master_bar,fastai.basic_train.progress_bar = master_bar,progress_bar
28
self.learn.callback_fns = self.orig_callback_fns
29
30