How to run without progress bar?

What should I pass in for pbar in order to not have a progress bar?

2 Likes

hey @source99, did you find the solution to your question?

Here you go. Hope it’s still helpful:

import fastai
from fastprogress import force_console_behavior
import fastprogress
fastprogress.fastprogress.NO_BAR = True
master_bar, progress_bar = force_console_behavior()
fastai.basic_train.master_bar, fastai.basic_train.progress_bar = master_bar, progress_bar

3 Likes

thanks @Farah, apart from what you said I had to add this line to hide printing the metrics, not very nice but it works:

fastprogress.fastprogress.WRITER_FN = str
1 Like

Thanks for sharing. I found this when searching for how to use fastai with hyperopt. Here’s a codeblock that seems to work for me

from hyperopt import fmin, tpe, hp
import fastai
from fastprogress import force_console_behavior
import fastprogress


space = [
    {'layer1': hp.choice('layer1',[2,5,10,25,50,100,250,500])},
    {'layer2': hp.choice('layer2',[2,5,10,25,50,100,250,500])},
    {'ps': hp.uniform('ps',0,1)},
    {'epochs': hp.randint('epochs',10)},
    {'lr': hp.choice('lr',[1e-1,5e-2,1e-2])},
]

def objective(x):
    # suppress widgets
    fastprogress.fastprogress.NO_BAR = True
    master_bar, progress_bar = force_console_behavior()
    fastai.basic_train.master_bar, fastai.basic_train.progress_bar = master_bar, progress_bar
    fastprogress.fastprogress.WRITER_FN = str
    
    # learn using params from hyperopt
    learn = tabular_learner(data, layers=[x[0]['layer1'],x[1]['layer2']], metrics=accuracy, ps=x[2]['ps'])
    learn.fit(x[3]['epochs']+1, x[4]['lr'])
    return {'loss':learn.recorder.val_losses[-1:][0], 'status':'ok'}

best = fmin(objective,
    space=space,
    algo=tpe.suggest,
    max_evals=100)
print(best)```
3 Likes

Incase anyone finds themselves here, to save you some digging around, there is a pattern that I think was just implemented that worked very well for me!

from fastai.utils.mod_display import *
with progress_disabled_ctx(learn) as learn:
        learn.fit_one_cycle(1)
6 Likes

None of the above examples worked for. I am trying to run a learner in a Linux terminal. No mater what I do, the progress bar throws and exception (division by zero). Is there no way to complete get rid of any UI elements when running the code in production?

Hi @MichaelHeliso, can you clarify your division by zero error? What kind of model are you training? And what are you passing in for a learning rate? I believe this may have to do with the training itself rather than the progress bar.

I am just making use of load_learner in order to load a learner previously saved. I have checked the data frame that is passed as test data and it is not empty. Same code works just fine if I run it via a notebook.

Thank you very much!