Giter Club home page Giter Club logo

fastprogress's Introduction

fastprogress

A fast and simple progress bar for Jupyter Notebook and console. Created by Sylvain Gugger for fast.ai.

Install

To install simply use

pip install fastprogress

or:

conda install -c fastai fastprogress

Note that this requires python 3.6 or later.

Usage

Example 1

Here is a simple example. Each bar takes an iterator as a main argument, and we can specify the second bar is nested with the first by adding the argument parent=mb. We can then:

  • add a comment in the first bar by changing the value of mb.main_bar.comment
  • add a comment in the second bar by changing the value of mb.child.comment
  • write a line between the two bars with mb.write('message')
from fastprogress.fastprogress import master_bar, progress_bar
from time import sleep
mb = master_bar(range(10))
for i in mb:
    for j in progress_bar(range(100), parent=mb):
        sleep(0.01)
        mb.child.comment = f'second bar stat'
    mb.main_bar.comment = f'first bar stat'
    mb.write(f'Finished loop {i}.')
    #mb.update_graph(graphs, x_bounds, y_bounds)

Example 2

To add a graph that get plots as the training goes, just use the command mb.update_graphs. It will create the figure on its first use. Arguments are:

  • graphs: a list of graphs to be plotted (each of the form [x,y])
  • x_bounds: the min and max values of the x axis (if None, it will those given by the graphs)
  • y_bounds: the min and max values of the y axis (if None, it will those given by the graphs)

Note that it's best to specify x_bounds and y_bounds, otherwise the box will change as the loop progresses.

Additionally, we can give the label of each graph via the command mb.names (should have as many elements as the graphs argument).

import numpy as np
mb = master_bar(range(10))
mb.names = ['cos', 'sin']
for i in mb:
    for j in progress_bar(range(100), parent=mb):
        if j%10 == 0:
            k = 100 * i + j
            x = np.arange(0, 2*k*np.pi/1000, 0.01)
            y1, y2 = np.cos(x), np.sin(x)
            graphs = [[x,y1], [x,y2]]
            x_bounds = [0, 2*np.pi]
            y_bounds = [-1,1]
            mb.update_graph(graphs, x_bounds, y_bounds)
            mb.child.comment = f'second bar stat'
    mb.main_bar.comment = f'first bar stat'
    mb.write(f'Finished loop {i}.')

Here is the rendering in console:

If the script using this is executed with a redirect to a file, only the results of the .write method will be printed in that file.

Example 3

Here is an example that a typical machine learning training loop can use. It also demonstrates how to set y_bounds dynamically.

def plot_loss_update(epoch, epochs, mb, train_loss, valid_loss):
    """ dynamically print the loss plot during the training/validation loop.
        expects epoch to start from 1.
    """
    x = range(1, epoch+1)
    y = np.concatenate((train_loss, valid_loss))
    graphs = [[x,train_loss], [x,valid_loss]]
    x_margin = 0.2
    y_margin = 0.05
    x_bounds = [1-x_margin, epochs+x_margin]
    y_bounds = [np.min(y)-y_margin, np.max(y)+y_margin]

    mb.update_graph(graphs, x_bounds, y_bounds)

And here is an emulation of a training loop that uses this function:

from fastprogress.fastprogress import master_bar, progress_bar
from time import sleep
import numpy as np
import random

epochs = 5
mb = master_bar(range(1, epochs+1))
# optional: graph legend: if not set, the default is 'train'/'valid'
# mb.names = ['first', 'second']
train_loss, valid_loss = [], []
for epoch in mb:
    # emulate train sub-loop
    for batch in progress_bar(range(2), parent=mb): sleep(0.2)
    train_loss.append(0.5 - 0.06 * epoch + random.uniform(0, 0.04))

    # emulate validation sub-loop
    for batch in progress_bar(range(2), parent=mb): sleep(0.2)
    valid_loss.append(0.5 - 0.03 * epoch + random.uniform(0, 0.04))

    plot_loss_update(epoch, epochs, mb, train_loss, valid_loss)

And the output:

Output


Copyright 2017 onwards, fast.ai. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. A copy of the License is provided in the LICENSE file in this repository.

fastprogress's People

Contributors

danielpcox avatar dependabot[bot] avatar jachoo avatar jpc avatar jph00 avatar lbin avatar mengman avatar michael-k avatar mkardas avatar mssandroid avatar scw avatar seem avatar sgugger avatar stas00 avatar takiholadi avatar tejasavinashshetty avatar ungvert avatar zcaceres avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastprogress's Issues

Updating a multiprocess progress_bar

I'm trying to replace a tqdm progress bar with a fastprogress bar. However, its not clear how to implement it for multiprocessing. Since gen is a required argument there does not seem to be an obvious way to allow processes to update the bar. Any instructions, or a pointer to an example, would be helpful.

ImportError: 'master_bar' from 'fastprogress'

Hi,

I am trying to import fastai and getting this error:

from fastai.imports import *
Traceback (most recent call last):

File "", line 1, in
from fastai.imports import *

File "C:\ProgramData\Anaconda3\lib\site-packages\fastai_init_.py", line 1, in
from .basic_train import *

File "C:\ProgramData\Anaconda3\lib\site-packages\fastai\basic_train.py", line 2, in
from .torch_core import *

File "C:\ProgramData\Anaconda3\lib\site-packages\fastai\torch_core.py", line 2, in
from .imports.torch import *

File "C:\ProgramData\Anaconda3\lib\site-packages\fastai\imports_init_.py", line 1, in
from .core import *

File "C:\ProgramData\Anaconda3\lib\site-packages\fastai\imports\core.py", line 15, in
from fastprogress import master_bar, progress_bar

ImportError: cannot import name 'master_bar' from 'fastprogress' (C:\ProgramData\Anaconda3\lib\site-packages\fastprogress_init_.py)

I am using anaconda (spyder) and I have installed fastai and fastprogress with following codes from anaconda prompt
conda install -c fastai fastprogress
conda install -c fastai fastai

Any suggestions? Thank you in advance.

Console progress bar takes two lines instead of one lines

image

Is this a bug or a feature?
I am not sure why I got two lines of the progress bar in my codes. I have tried running the Examples.ipynb and it only has one line for the console progress bar.

How to make it display only on one line instead of two?

Difference with tqdm

Hi,

Thanks for your project. Would you please mention differences (implemented or planned) between fast_progress and tqdm in README or somewhere?

Change the size of the figure

Currently the size of the update graph is fixed, is there any way to change the size of the figure, or better yet, allow us to run arbitrary plot function? Thanks!

Master bar not showing in console

The master bar is not showing on console.

bar = master_bar(range(10))
for e in bar:
    for i in progress_bar(range(10), parent=bar):
        sleep(0.05)

On the notebook I get what I want, but not on the terminal.
image
But on console only get the child bar:
image

AttributeError: 'NoneType' object has no attribute 'update'

Running the example from https://pypi.org/project/fastprogress/ below:

from fastprogress import master_bar, progress_bar
from time import sleep
mb = master_bar(range(10))
for i in mb:
    for j in progress_bar(range(100), parent=mb):
        sleep(0.01)
        mb.child.comment = f'second bar stat'
    mb.first_bar.comment = f'first bar stat'
    mb.write(f'Finished loop {i}.')
    #mb.update_graph(graphs, x_bounds, y_bounds)

returns the error:

AttributeError: 'NoneType' object has no attribute 'update'

I have tried this on both a Mac and PC running Python 3.6.1

Google Colaboratory support

When I used fast progress in Google Colaboratory, I found this error

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-d93e865ab2ed> in <module>()
----> 1 from fast_progress import master_bar, progress_bar
      2 from time import sleep

/content/fast_progress.py in <module>()
      7 
      8 if IN_NOTEBOOK:
----> 9     from ipywidgets import widgets, IntProgress, HBox, HTML, VBox
     10     from IPython.display import clear_output
     11     from ipywidgets.widgets.interaction import show_inline_matplotlib_plots

ModuleNotFoundError: No module named 'ipywidgets'

So, please also check that it's within Colab, and revert to console version.
Colab can display HTML just fine, and also allow JS<->Python communication.
So, someone can try to implement a Colab-specific version as well.

VersionConflict in fastprogress

Please, I'm using Google Colab and Python3:

!curl -s https://course.fast.ai/setup/colab | bash
import warnings
warnings.filterwarnings('ignore')
from fastai.vision import *
from fastai.metrics import error_rate
import fastai
print(f'fastai: {fastai.__version__}')
print(f'cuda: {torch.cuda.is_available()}')

I have this error of VersionConflict:
---------------------------------------------------------------------------
VersionConflict                           Traceback (most recent call last)
<ipython-input-17-01736c3668f8> in <module>()
      1 import warnings
      2 warnings.filterwarnings('ignore')
----> 3 from fastai.vision import *
      4 from fastai.metrics import error_rate
      5 import fastai

7 frames
/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting, extras)
    789                 # Oops, the "best" so far conflicts with a dependency
    790                 dependent_req = required_by[req]
--> 791                 raise VersionConflict(dist, req).with_context(dependent_req)
    792 
    793             # push the new requirements onto the stack

VersionConflict: (fastprogress 0.1.22 (/usr/local/lib/python3.6/dist-packages), Requirement.parse('fastprogress>=0.2.1'))

Does anyone know the reason?

Not Working in VisualStudioCode/Python extension

Since end of October, VisualStudioCode supports python, IPython and Jupyter Notebook - see this repo as an example. Now running the progress bar example

#%%
from fastprogress import master_bar, progress_bar
from time import sleep
mb = master_bar(range(10))
for i in mb:
    for j in progress_bar(range(100), parent=mb):
        sleep(0.01)
        mb.child.comment = f'second bar stat'
    mb.first_bar.comment = f'first bar stat'
    mb.write(f'Finished loop {i}.')
    #mb.update_graph(graphs, x_bounds, y_bounds)

does not properly update the UI, thus resulting in this output.

schermata 2018-11-16 alle 10 43 31

The animation is now showed in the UI basically. Runnable example is here

null self.out in `if self.display: self.out.update(HTML(self.progress))`

src = ItemLists(path, TextList(train_tok, path=path, processor=processor),
                TextList(valid_tok, path=path, processor=processor))
src = src.label_for_lm()

Produces this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-f14467f55f2d> in <module>()
      4 src = ItemLists(path, TextList(train_tok, path=path, processor=processor),
      5                 TextList(valid_tok, path=path, processor=processor))
----> 6 src = src.label_for_lm()
      7 if test_tok is not None: src.add_test(TextList(test_tok, path=path))
      8 text_data = src.databunch()

/Users/ben/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in _inner(*args, **kwargs)
    466             self.valid = fv(*args, from_item_lists=True, **kwargs)
    467             self.__class__ = LabelLists
--> 468             self.process()
    469             return self
    470         return _inner

/Users/ben/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self)
    520         "Process the inner datasets."
    521         xp,yp = self.get_processors()
--> 522         for ds,n in zip(self.lists, ['train','valid','test']): ds.process(xp, yp, name=n)
    523         #progress_bar clear the outputs so in some case warnings issued during processing disappear.
    524         for ds in self.lists:

/Users/ben/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self, xp, yp, name)
    697                     p.warns = []
    698                 self.x,self.y = self.x[~filt],self.y[~filt]
--> 699         self.x.process(xp)
    700         return self
    701 

/Users/ben/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in process(self, processor)
     73         if processor is not None: self.processor = processor
     74         self.processor = listify(self.processor)
---> 75         for p in self.processor: p.process(self)
     76         return self
     77 

/Users/ben/anaconda3/lib/python3.6/site-packages/fastai/text/data.py in process(self, ds)
    290         ds.items = _join_texts(ds.items, self.mark_fields, self.include_bos, self.include_eos)
    291         tokens = []
--> 292         for i in progress_bar(range(0,len(ds),self.chunksize), leave=False):
    293             tokens += self.tokenizer.process_all(ds.items[i:i+self.chunksize])
    294         ds.items = tokens

/Users/ben/anaconda3/lib/python3.6/site-packages/fastprogress/fastprogress.py in __iter__(self)
     62     def __iter__(self):
     63         self.on_iter_begin()
---> 64         self.update(0)
     65         try:
     66             for i,o in enumerate(self._gen):

/Users/ben/anaconda3/lib/python3.6/site-packages/fastprogress/fastprogress.py in update(self, val)
     77             self.pred_t = 0
     78             self.last_v,self.wait_for = 0,1
---> 79             self.update_bar(0)
     80         elif val >= self.last_v + self.wait_for or val == self.total:
     81             cur_t = time()

/Users/ben/anaconda3/lib/python3.6/site-packages/fastprogress/fastprogress.py in update_bar(self, val)
     96             warn("Your generator is empty.")
     97             self.on_update(0, '100% [0/0]')
---> 98         else: self.on_update(val, f'{100 * val/self.total:.2f}% [{val}/{self.total} {elapsed_t}<{remaining_t}{end}]')
     99 
    100 

/Users/ben/anaconda3/lib/python3.6/site-packages/fastprogress/fastprogress.py in on_update(self, val, text, interrupted)
    167     def on_update(self, val, text, interrupted=False):
    168         self.progress = html_progress_bar(val, self.total, text, interrupted)
--> 169         if self.display: self.out.update(HTML(self.progress))
    170         elif self.parent is not None: self.parent.show()
    171 

AttributeError: 'NoneType' object has no attribute 'update'

Question: Hook to replace ConsoleProgressBar print statements

It is not an issue per se, however, I wonder is it possible to modify ConsoleProgressBar class a bit to make possible to replace print calls with something like self.write, and allow to insert your own writer?

I know that Python allows you to redirect stdin with a special context manager but it would be more suitable for one to use custom output method. Because, for example, if you're using logging, you need to do the work twice, i.e., setup logger, and redirect stream. And if the progress bar could be configurable, then you could just pass logger instance inside or something.

I mean, something like this (shouldn't be exactly this solution, of course):

class ConsoleProgressBar(ProgressBar):
    length:int=50
    fill:str='█'

    def __init__(self, gen, total=None, display=True, leave=True,
                       parent=None, auto_update=True, writer_fn=print):

        self.max_len,self.prefix = 0,''
        super().__init__(gen, total, display, leave, parent, auto_update)
        self.write = writer_fn

    def on_iter_end(self):
        if not self.leave and printing():
            self.write(f'\r{self.prefix}' + ' ' * (self.max_len - len(f'\r{self.prefix}')), end = '\r')

    def on_update(self, val, text):
        if self.display:
            filled_len = int(self.length * val // self.total)
            bar = self.fill * filled_len + '-' * (self.length - filled_len)
            to_write = f'\r{self.prefix} |{bar}| {text}'
            if len(to_write) > self.max_len: self.max_len=len(to_write)
            if printing(): self.write(to_write, end = '\r')

AttributeError: 'NBMasterBar' object has no attribute 'out'

from the 10_nlp.ipynb, trying to fine tune the language model

learn.fit_one_cycle(1, 2e-2)


AssertionError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
187 try:
--> 188 self._do_begin_fit(n_epoch)
189 for epoch in range(n_epoch):

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in _do_begin_fit(self, n_epoch)
159 def _do_begin_fit(self, n_epoch):
--> 160 self.n_epoch,self.loss = n_epoch,tensor(0.); self('begin_fit')
161

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in call(self, event_name)
123
--> 124 def call(self, event_name): L(event_name).map(self._call_one)
125 def _call_one(self, event_name):

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, *args, **kwargs)
371 else f.getitem)
--> 372 return self._new(map(g, self))
373

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
322 def _xtra(self): return None
--> 323 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
324 def getitem(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in call(cls, x, args, **kwargs)
40
---> 41 res = super().call(
((x,) + args), **kwargs)
42 res._newchk = 0

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in init(self, items, use_list, match, *rest)
313 if (use_list is not None) or not _is_array(items):
--> 314 items = list(items) if use_list else _listify(items)
315 if match is not None:

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _listify(o)
249 if isinstance(o, str) or _is_array(o): return [o]
--> 250 if is_iter(o): return list(o)
251 return [o]

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in call(self, *args, **kwargs)
215 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 216 return self.fn(*fargs, **kwargs)
217

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in _call_one(self, event_name)
126 assert hasattr(event, event_name)
--> 127 [cb(event_name) for cb in sort_by_run(self.cbs)]
128

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in (.0)
126 assert hasattr(event, event_name)
--> 127 [cb(event_name) for cb in sort_by_run(self.cbs)]
128

/opt/conda/lib/python3.7/site-packages/fastai2/callback/core.py in call(self, event_name)
23 (self.run_valid and not getattr(self, 'training', False)))
---> 24 if self.run and _run: getattr(self, event_name, noop)()
25 if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit

/opt/conda/lib/python3.7/site-packages/fastai2/callback/fp16.py in begin_fit(self)
83 def begin_fit(self):
---> 84 assert self.dls.device.type == 'cuda', "Mixed-precision training requires a GPU, remove the call to_fp16"
85 if self.learn.opt is None: self.learn.create_opt()

AssertionError: Mixed-precision training requires a GPU, remove the call to_fp16

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
in
----> 1 learn.fit_one_cycle(1, 2e-2)

/opt/conda/lib/python3.7/site-packages/fastai2/callback/schedule.py in fit_one_cycle(self, n_epoch, lr_max, div, div_final, pct_start, wd, moms, cbs, reset_opt)
110 scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final),
111 'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))}
--> 112 self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd)
113
114 # Cell

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
196
197 except CancelFitException: self('after_cancel_fit')
--> 198 finally: self('after_fit')
199
200 def validate(self, ds_idx=1, dl=None, cbs=None):

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in call(self, event_name)
122 def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)]
123
--> 124 def call(self, event_name): L(event_name).map(self._call_one)
125 def _call_one(self, event_name):
126 assert hasattr(event, event_name)

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, *args, **kwargs)
370 else f.format if isinstance(f,str)
371 else f.getitem)
--> 372 return self._new(map(g, self))
373
374 def filter(self, f, negate=False, **kwargs):

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
321 @Property
322 def _xtra(self): return None
--> 323 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
324 def getitem(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
325 def copy(self): return self._new(self.items.copy())

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in call(cls, x, args, **kwargs)
39 return x
40
---> 41 res = super().call(
((x,) + args), **kwargs)
42 res._newchk = 0
43 return res

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in init(self, items, use_list, match, *rest)
312 if items is None: items = []
313 if (use_list is not None) or not _is_array(items):
--> 314 items = list(items) if use_list else _listify(items)
315 if match is not None:
316 if is_coll(match): match = len(match)

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _listify(o)
248 if isinstance(o, list): return o
249 if isinstance(o, str) or _is_array(o): return [o]
--> 250 if is_iter(o): return list(o)
251 return [o]
252

/opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in call(self, *args, **kwargs)
214 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
215 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 216 return self.fn(*fargs, **kwargs)
217
218 # Cell

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in _call_one(self, event_name)
125 def _call_one(self, event_name):
126 assert hasattr(event, event_name)
--> 127 [cb(event_name) for cb in sort_by_run(self.cbs)]
128
129 def _bn_bias_state(self, with_bias): return bn_bias_params(self.model, with_bias).map(self.opt.state)

/opt/conda/lib/python3.7/site-packages/fastai2/learner.py in (.0)
125 def _call_one(self, event_name):
126 assert hasattr(event, event_name)
--> 127 [cb(event_name) for cb in sort_by_run(self.cbs)]
128
129 def _bn_bias_state(self, with_bias): return bn_bias_params(self.model, with_bias).map(self.opt.state)

/opt/conda/lib/python3.7/site-packages/fastai2/callback/core.py in call(self, event_name)
22 _run = (event_name not in _inner_loop or (self.run_train and getattr(self, 'training', True)) or
23 (self.run_valid and not getattr(self, 'training', False)))
---> 24 if self.run and _run: getattr(self, event_name, noop)()
25 if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
26

/opt/conda/lib/python3.7/site-packages/fastai2/callback/progress.py in after_fit(self)
37 def after_fit(self):
38 if getattr(self, 'mbar', False):
---> 39 self.mbar.on_iter_end()
40 delattr(self, 'mbar')
41 self.learn.logger = self.old_logger

/opt/conda/lib/python3.7/site-packages/fastprogress/fastprogress.py in on_iter_end(self)
155 total_time = format_time(time.time() - self.main_bar.start_t)
156 self.text = f'Total time: {total_time}

' + self.text
--> 157 self.out.update(HTML(self.text))
158
159 def add_child(self, child):

AttributeError: 'NBMasterBar' object has no attribute 'out'

f' String ' ERROR!!!!

My python version is 3.5.2. In my python, all f'balabala ~' is error. it shows invalid syntax, so i can not run anything!! I can replace f'string' with r'string', but why using f'string'?

ImportError: cannot import name 'master_bar' in v0.2.1

V0.2.1 of fastprogress released a couple of days ago seems to cause errors when importing master_bar and progress_bar:

>>> from fastprogress import master_bar, progress_bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'master_bar'

Tested on a fresh Ubuntu 18.04 install.

As a workaround, users need to downgrade: pip3 install fastprogress==0.1.22

Not working in jupyter console

Is there a way to get console behavior in Jupyter console? Currently it just says <IPython.core.display.HTML object>

Jupyter console 6.0.0

Python 3.7.1 (default, Dec 14 2018, 19:28:38)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: get_ipython().__class__.__name__
Out[1]: 'ZMQInteractiveShell'

In [2]: from fastprogress import master_bar, progress_bar
      : from time import sleep
      : mb = master_bar(range(10))
      : for i in mb:
      :     for j in progress_bar(range(100), parent=mb):
      :         sleep(0.01)
      :
<IPython.core.display.HTML object>

UnicodeEncodeError ascii' codec can't encode characters

Am trying to run a training job using fastai in a Docker container (not Jupyter notebook) and getting a UnicodeEncodeError in the fastprogress library. Am running fastprogress version 0.1.15, fastai version 1.0.28 with Python v3.6.

Full stack trace includes the following:

algo-1-3QNM9_1_51756cf5708d | Called _train method with model arch: resnet34, batch size: 64, image size: 224, epochs: 4
algo-1-3QNM9_1_51756cf5708d | Getting training data from dir: /opt/ml/input/data/training
algo-1-3QNM9_1_51756cf5708d | Model architecture is resnet34
algo-1-3QNM9_1_51756cf5708d | Creating pretrained conv net
algo-1-3QNM9_1_51756cf5708d | Downloading: "https://download.pytorch.org/models/resnet34-333f7ec4.pth" to /root/.torch/models/resnet34-333f7ec4.pth
100% 87306240/87306240 [00:01<00:00, 70374700.25it/s]
algo-1-3QNM9_1_51756cf5708d | Fit four cycles
algo-1-3QNM9_1_51756cf5708d | epoch  train_loss  valid_loss  accuracy
/usr/local/lib/python3.6/dist-packages/PIL/Image.py:953: UserWarning: Palette images with Transparency   expressed in bytes should be converted to RGBA images
algo-1-3QNM9_1_51756cf5708d |   'to RGBA images')
Traceback (most recent call last):                                                              
algo-1-3QNM9_1_51756cf5708d |   File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
algo-1-3QNM9_1_51756cf5708d |     "__main__", mod_spec)
algo-1-3QNM9_1_51756cf5708d |   File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
algo-1-3QNM9_1_51756cf5708d |     exec(code, run_globals)
algo-1-3QNM9_1_51756cf5708d |   File "/opt/ml/code/shirts.py", line 152, in <module>
algo-1-3QNM9_1_51756cf5708d |     _train(parser.parse_args())
algo-1-3QNM9_1_51756cf5708d |   File "/opt/ml/code/shirts.py", line 66, in _train
algo-1-3QNM9_1_51756cf5708d |     learn.fit_one_cycle(4)
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastai/train.py", line 20, in fit_one_cycle
algo-1-3QNM9_1_51756cf5708d |     learn.fit(cyc_len, max_lr, wd=wd, callbacks=callbacks)
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py", line 162, in fit
algo-1-3QNM9_1_51756cf5708d |     callbacks=self.callbacks+callbacks)
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py", line 94, in fit
algo-1-3QNM9_1_51756cf5708d |     raise e
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py", line 82, in fit
algo-1-3QNM9_1_51756cf5708d |     for xb,yb in progress_bar(data.train_dl, parent=pbar):
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastprogress/fastprogress.py", line 67, in __iter__
algo-1-3QNM9_1_51756cf5708d |     if self.auto_update: self.update(i+1)
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastprogress/fastprogress.py", line 85, in update
algo-1-3QNM9_1_51756cf5708d |     self.update_bar(val)
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastprogress/fastprogress.py", line 97, in update_bar
algo-1-3QNM9_1_51756cf5708d |     else: self.on_update(val, f'{100 * val/self.total:.2f}% [{val}/{self.total} {elapsed_t}<{remaining_t}{end}]')
algo-1-3QNM9_1_51756cf5708d |   File "/usr/local/lib/python3.6/dist-packages/fastprogress/fastprogress.py", line 262, in on_update
algo-1-3QNM9_1_51756cf5708d |     if printing(): WRITER_FN(to_write, end = '\r')
algo-1-3QNM9_1_51756cf5708d | UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-15: ordinal not in range(128)
algo-1-3QNM9_1_51756cf5708d | 2018-11-20 08:10:39,646 sagemaker-containers ERROR    ExecuteUserScriptError:
algo-1-3QNM9_1_51756cf5708d | Command "/usr/local/bin/python -m shirts --batch-size 64 --epochs 4"

fastprogress in console mode locks up emacs

I am using fastprogress through emacs -- using emacs's inferior-python-mode and elpy. When I invoke a function (through PyMC3) that uses fastprogress, it takes over input to the editor until the python call using fastprogress terminates. Also, it takes the current cursor and pulls it out of whatever editor buffer it was in and puts it into the interactive python buffer.

My guess is that this has something to do with the way that fp is writing its output to the console. Is it perhaps sending characters to it one at a time to write the progress bar?

progress_bar not displayed

Hi there!

I installed fastprogress using pip. I am trying to use this in order to create a progressbar for the sake of measuring time required to parse all the documents using spacy.

The issue is that the progressbar is not being displayed. Can you please help me with the same? I have tried to create a toy example to demonstrate the same below.

image

As seen above, there's a small progressbar with no comment and it's static all the while.

Can you please help me with this?

With Regards,
Vinayak.

Progress bar (pymc 3.9) does not work with Voila-dashboard view

Hello,

I was trying to use pymc3 (3.9.2) with Voila (https://voila.readthedocs.io/en/stable/) and I cannot see the progress bar running in the Voila-dashboard view (it works fine with the classic notebook). All i see is a grey box:

1

But when i use pymc3 (3.7), which has the older version of progress bar, I can see the progress bar running just fine.

You can check it here:
https://mybinder.org/v2/gist/atharvahans1/68044ff6d1f093b7d1d788929231754d/master

How can I fix this?

Thanks,
Atharva

Unexpected kwarg Auto-update TypeError on Colab (Python 3.6)

Hi,

while going through the course-v3/dl2 notebooks (from 09c onwards) on Google Colab, found this bug.
TypeError: init() got an unexpected keyword argument 'auto_update'

The origin looks like to be a lack of "auto_update" kwargs.

imatge

Commenting the "auto-update=False " is enought to bypass the error.

imatge

I've checked the installed version of fastprogress and it happens to be 0.2.2

Thanks,

Ed


TypeError Traceback (most recent call last)

in ()
----> 1 learn.fit(40, cbsched)

5 frames

/content/drive/My Drive/colab/course-v3/nbs/dl2/exp/nb_09b.py in fit(self, epochs, cbs, reset_opt)
69 self.do_begin_fit(epochs)
70 for epoch in range(epochs):
---> 71 self.do_begin_epoch(epoch)
72 if not self('begin_epoch'): self.all_batches()
73

/content/drive/My Drive/colab/course-v3/nbs/dl2/exp/nb_09b.py in do_begin_epoch(self, epoch)
58 def do_begin_epoch(self, epoch):
59 self.epoch,self.dl = epoch,self.data.train_dl
---> 60 return self('begin_epoch')
61
62 def fit(self, epochs, cbs=None, reset_opt=False):

/content/drive/My Drive/colab/course-v3/nbs/dl2/exp/nb_09b.py in call(self, cb_name)
90 res = False
91 assert cb_name in self.ALL_CBS
---> 92 for cb in sorted(self.cbs, key=lambda x: x._order): res = cb(cb_name) and res
93 return res
94

/content/drive/My Drive/colab/course-v3/nbs/dl2/exp/nb_05b.py in call(self, cb_name)
19 def call(self, cb_name):
20 f = getattr(self, cb_name, None)
---> 21 if f and f(): return True
22 return False
23

/content/drive/My Drive/colab/course-v3/nbs/dl2/exp/nb_09c.py in begin_epoch(self)
45 def after_fit(self): self.mbar.on_iter_end()
46 def after_batch(self): self.pb.update(self.iter)
---> 47 def begin_epoch (self): self.set_pb()
48 def begin_validate(self): self.set_pb()
49

/content/drive/My Drive/colab/course-v3/nbs/dl2/exp/nb_09c.py in set_pb(self)
49
50 def set_pb(self):
---> 51 self.pb = progress_bar(self.dl, parent=self.mbar, auto_update=False)
52 self.mbar.update(self.epoch)

TypeError: init() got an unexpected keyword argument 'auto_update'

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Hi there,
I got an error

File "/home/venv/lib/python3.7/site-packages/fastprogress/fastprogress.py", line 264, in add_child
    self.child.prefix = f'Epoch {self.main_bar.last_v+1}/{self.main_bar.total} :'
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

I solved it by commenting that particular line. But, is there any better workaround for this? Because the workaround I did means that I have to change the script in the installation.

Thanks!

AttributeError: 'NBMasterBar' object has no attribute 'first_bar'

Trying out the following example on Colab:

from fastprogress.fastprogress import master_bar, progress_bar
from time import sleep
mb = master_bar(range(10))
for i in mb:
    for j in progress_bar(range(100), parent=mb):
        sleep(0.01)
        mb.child.comment = f'second bar stat'
    mb.first_bar.comment = f'first bar stat'
    mb.write(f'Finished loop {i}.')

Throws: AttributeError: 'NBMasterBar' object has no attribute 'first_bar'.

Undefined name: 'display' in ./fast_progress/fast_progress.py

Probably just a missing import statement...

flake8 testing of https://github.com/fastai/fast_progress on Python 3.7.0

$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

/home/travis/virtualenv/python3.7.0/lib/python3.7/site-packages/pycodestyle.py:113: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
./fast_progress/fast_progress.py:92:26: F821 undefined name 'display'
        if self.display: display(self.box)
                         ^
./fast_progress/fast_progress.py:116:30: F821 undefined name 'display'
    def on_iter_begin(self): display(self.vbox)
                             ^
./fast_progress/fast_progress.py:140:13: F821 undefined name 'display'
            display(self.ax.figure)
            ^
3     F821 undefined name 'display'
3

Passing pymongo query to progress_bar

Trying to pass a pymongo query to progress_bar results in the error below. I can fix this by passing my pymongo query in as a list i.e. progress_bar(list(x))

But would it be possible/desirable to handle this coercion internally to fastprogress?

/opt/anaconda3/lib/python3.7/site-packages/fastprogress/fastprogress.py in __init__(self, gen, total, display, leave, parent, auto_update)
    144 class NBProgressBar(ProgressBar):
    145     def __init__(self, gen, total=None, display=True, leave=True, parent=None, auto_update=True):
--> 146         self.progress = html_progress_bar(0, len(gen) if total is None else total, "")
    147         super().__init__(gen, total, display, leave, parent, auto_update)
    148 

TypeError: object of type 'Cursor' has no len()

Missing GitHub Release artifacts since v0.1.22

Thank you for this awesome package!

While working on fastprogress recipe for conda-forge in conda-forge/staged-recipes#10658, I noticed some discrepancies between releases on GitHub and the ones available on PyPI. GitHub Release artifacts aren't available since v0.1.22 (November):

  • GitHub Releases
    Screen Shot 2020-01-21 at 4 37 51 PM

  • PyPI Releases
    Screen Shot 2020-01-21 at 4 30 46 PM

I am wondering if these missing artifacts are available somewhere else? I am asking because I had a hard time building the conda-forge package for fastprogress using the tarbar from PyPI.

Thank you!

got an unexpected keyword argument 'flush'

  File "C:\Anaconda\envs\fv\lib\site-packages\fastprogress\fastprogress.py", line 247, in on_update
    if printing(): WRITER_FN(to_write, end=end, flush=FLUSH)
TypeError: log_fastai_msg() got an unexpected keyword argument 'flush'

hi,
any ideas why i am getting this error ?

if i try it out in the console it works, but when i run my fastai code i get the error.

WRITER_FN = print
WRITER_FN("hello", flush=True)

the above two lines work for me in a python console.

thanks!

Encountered this error

Traceback (most recent call last):                                                                                       
  File "depth_fast.py", line 82, in <module>
    ftrain.fit_one_cycle(main_model, 1)
  File "/home/pranay/anaconda3/lib/python3.6/site-packages/fastai/train.py", line 22, in fit_one_cycle
    learn.fit(cyc_len, max_lr, wd=wd, callbacks=callbacks)
  File "/home/pranay/anaconda3/lib/python3.6/site-packages/fastai/basic_train.py", line 191, in fit
    callbacks=self.callbacks+callbacks)
  File "/home/pranay/anaconda3/lib/python3.6/site-packages/fastai/basic_train.py", line 92, in fit
    for xb,yb in progress_bar(data.train_dl, parent=pbar):
ValueError: too many values to unpack (expected 2)

name 'HTML' is not defined

When I'm trying to run the following from fast.ai v3 lesson 3 IMDB notebook:

data_lm = TextDataBunch.from_csv(path, 'texts.csv')

I get the following error:

/opt/conda/lib/python3.7/site-packages/fastprogress/fastprogress.py in on_iter_begin(self)
    160 
    161     def on_iter_begin(self):
--> 162         if self.display: self.out = display(HTML(self.progress), display_id=True)
    163         self.is_active=True
    164 

NameError: name 'HTML' is not defined

Here are the library versions:

  • fastai-1.0.52
  • fastprogress-0.1.21

ImportError: cannot import name 'master_bar'

`---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in
----> 1 from fastai.vision import *
2 from fastai.metrics import error_rate

~\Anaconda3\envs\fastai\lib\site-packages\fastai_init_.py in
----> 1 from .basic_train import *
2 from .callback import *
3 #from .callbacks import *
4 from .core import *
5 from .basic_data import *

~\Anaconda3\envs\fastai\lib\site-packages\fastai\basic_train.py in
1 "Provides basic training and validation with Learner"
----> 2 from .torch_core import *
3 from .basic_data import *
4 from .callback import *
5

~\Anaconda3\envs\fastai\lib\site-packages\fastai\torch_core.py in
1 "Utility functions to help deal with tensors"
----> 2 from .imports.torch import *
3 from .core import *
4
5 AffineMatrix = Tensor

~\Anaconda3\envs\fastai\lib\site-packages\fastai\imports_init_.py in
----> 1 from .core import *
2 from .torch import *

~\Anaconda3\envs\fastai\lib\site-packages\fastai\imports\core.py in
13 from dataclasses import dataclass, field
14 from enum import Enum, IntEnum
---> 15 from fastprogress import master_bar, progress_bar
16 from functools import partial, reduce, singledispatch
17 from pdb import set_trace

ImportError: cannot import name 'master_bar'
`
What's happening?

Reloading of Browser looses all of the output in jupyter notebook

Using the fastai library, I am using a computing EC2 machine with a jupyter notebook to train models using fastai lib.

However, when I reload the notebook, the cells that where running while I closed the browser tab do not display any output.

Is there any way to fix this? Maybe setting some top level config in the notebook to revert to the console output?

Im using Ubuntu 18.04 LTS chrome.

ZeroDivisionError for `progress_bar` in Console for empty iterables

Progress Bar is failing for empty iterables in console.

It works fine in notebook:
image

But in Console it doesn't work:
image

Code snippet used:

import fastprogress
from fastprogress import progress_bar, master_bar
fastprogress.__version__

# I have a variable length list, which can also be empty

variable_len_list = [] # special case of empty lisy

for x in variable_len_list:
    # do some compute
    sleep(10)

for x in master_bar(variable_len_list):
    # do some compute
    sleep(10)

for x in progress_bar(variable_len_list):
    # do some compute
    sleep(10)

High CPU load in Safari

When running in JupyterLab in Safari the latest fastprogress has a very high CPU load, up to 100% on a relatively modern machine.

Profiling shows that Safari is spending almost all its time in loops of WebCore::Document::updateStyleIfNeeded. CPU load returns to normal if I remove everything from the <style> block of html_progress_bar, but then, of course, I get a generic progress bar style rather than one like that shown in the README.

UnicodeEncodeError: 'latin-1' codec can't encode character '\u2588'

I am using Fast-bert, which uses fastprogress under the hood, an encountered an encoding issue while running a script from a CentOS Linux server terminal.

Please note that this same issue is referred in #21, and the workaround of setting the LC_ALL environment variable to C.UTF-8 does not work, but it works to set it to en_US.UTF-8.

$ setenv LC_ALL en_US.UTF-8

Anyway, I think this should be solved, as this is just a temporal workaround (you have to set it again every day) and it is a simple encoding error which is severely breaking other libraries which depends on fastprogress.

This is the full traceback, but in summary the problem is the '\u2588' (full-block) character, which is used to fill the progress bar.

Traceback (most recent call last):
  File "Train-FastBert.py", line 92, in <module>
    tr_manager.train(data_holder)
  File "/gscratch2/users/ablanco061/PhD_workspace/MIMICOsa_workspace/scripts/fast-bert/train/tr_bin/train_manager.py", line 20, in train
    self.custom_model.learner.fit(data_holder.epochs, data_holder.learning_rate, validate=True)
  File "/gscratch2/users/ablanco061/libs_custom/alber_venv_gpu/lib/python3.6/site-packages/fast_bert/learner_cls.py", line 276, in fit
    for step, batch in enumerate(progress_bar(train_dataloader, parent=pbar)):
  File "/gscratch2/users/ablanco061/libs_custom/alber_venv_gpu/lib/python3.6/site-packages/fastprogress/fastprogress.py", line 75, in __iter__
    if self.auto_update: self.update(i+1)
  File "/gscratch2/users/ablanco061/libs_custom/alber_venv_gpu/lib/python3.6/site-packages/fastprogress/fastprogress.py", line 92, in update
    self.update_bar(val)
  File "/gscratch2/users/ablanco061/libs_custom/alber_venv_gpu/lib/python3.6/site-packages/fastprogress/fastprogress.py", line 104, in update_bar
    else: self.on_update(val, f'{100 * val/self.total:.2f}% [{val}/{self.total} {elapsed_t}<{remaining_t}{end}]')
  File "/gscratch2/users/ablanco061/libs_custom/alber_venv_gpu/lib/python3.6/site-packages/fastprogress/fastprogress.py", line 274, in on_update
    if printing(): WRITER_FN(to_write, end = '\r')
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2588' in position 14: ordinal not in range(256)

I guess that a potencial solution could be checking the encoding which the user has and selecting the corresponding fill character (one that does not cause an encoding error)

If you need something else in order to fix the error, please count on me.

Can not continue to see the message using table = False written in progress runtime

from fastprogress import master_bar, progress_bar
from time import sleep
mb = master_bar(range(10))
for i in mb:
    for j in progress_bar(range(100), parent=mb):
        sleep(0.01)
        mb.child.comment = f'second bar stat'
    mb.first_bar.comment = f'first bar stat'
    mb.write(f'no_table{i}.') # This message cannot be displayed continuously at runtime
    mb.write(f'use_table{i}',table=True)

In the notebook,I tried to insert some messages with write() between the two progress bars, and the message written with table=False would be overwritten with the message written by table=True. While all can be displayed at the end of the run, but I can not continue to see the message using table = False written in progress runtime.

Is there a way to deal with variable sized iterables?

The problem is this line:
self.total = len(gen) if total is None else total

That is executed at the beginning. But len(gen) might change throughout the iteration, but progress_bar just assumes it keeps still.

What I really want is to use a timer (so "train for 1 hour" instead of "train for so and so epochs").

import time
class Timer:
    def __init__(self, num_seconds):
        self.num_seconds = num_seconds
        self.i = None
        
    def __len__(self):
        if self.i is None: return 1
        eps = 1e-7
        t = time.time() - self.start
        progress = t/num_seconds
        return int((num_seconds*self.i)/(progress+eps)) # estimated size. Changes constantly.
    
    def __iter__(self):
        self.start = time.time()
        self.i, t = 0, 0.0
        while t <= self.num_seconds:
            t = time.time() - self.start
            self.i += 1
            yield None

With this class, if you write

for t in Timer(3.0):
    # do stuff

it runs for 3 seconds. But it doesn't work with the progress_bar :(

Plot placement

Is it possible to show plot above all other information?
What I mean:


|plot_____________|
|plot_____________|
|plot_____________|
progress bar1
progress bar2
.....................

Progress Bar on Pycharm?

Hi I'm currently using Pycharm to run remote jupyter server, but when I'm training (using fastai2), the progress bar simply grey and not running at all (the train still ran and finished)
Thank you!
ảnh

AttributeError: 'NBMasterBar' object has no attribute 'out'

When using learner.fit_flat_cos(n_epochs, cbs=[SaveModelCallback(path)]) it throws the exception
However when used without the callback, it works with no error

fast_progress version = fastprogress-0.2.2

Any idea of what is causing this bug ?

cannot import name 'master_bar' from 'fastprogress'

I used spyder and jupyter notebook from Anaconda 64-bit and recently I installed fastai 1.0.34 in a virtual environment using

conda install -v -v fastai fastai.

The system checked all dependencies and asked if I want to proceed with fastai 1.0.34. I agreed and the process continued. I could see my installed package in that environment. To verify that my installation was correct, I ran

from fastai import *

I got the following error. What should I do?

ImportError Traceback (most recent call last)
in
----> 1 from fastai import *

~\Anaconda3\envs\fastai_env\lib\site-packages\fastai_init_.py in
----> 1 from .basic_train import *
2 from .callback import *
3 #from .callbacks import *
4 from .core import *
5 from .basic_data import *

~\Anaconda3\envs\fastai_env\lib\site-packages\fastai\basic_train.py in
1 "Provides basic training and validation with Learner"
----> 2 from .torch_core import *
3 from .basic_data import *
4 from .callback import *
5

~\Anaconda3\envs\fastai_env\lib\site-packages\fastai\torch_core.py in
1 "Utility functions to help deal with tensors"
----> 2 from .imports.torch import *
3 from .core import *
4
5 AffineMatrix = Tensor

~\Anaconda3\envs\fastai_env\lib\site-packages\fastai\imports_init_.py in
----> 1 from .core import *
2 from .torch import *

~\Anaconda3\envs\fastai_env\lib\site-packages\fastai\imports\core.py in
13 from dataclasses import dataclass, field
14 from enum import Enum, IntEnum
---> 15 from fastprogress import master_bar, progress_bar
16 from functools import partial, reduce, singledispatch
17 from pdb import set_trace

ImportError: cannot import name 'master_bar' from 'fastprogress' (C:\Users\hferdina\Anaconda3\envs\fastai_env\lib\site-packages\fastprogress_init_.py)

Use of figsize kwarg causes error in console but not notebook

I have a traceback complaining of an unexpected kwarg 'figsize' when running outside of a notebook, but not when running in a notebook, or even when running in nbdev_test_nbs.

I think I can see what's up: According to these lines, the master_bar is a completely different class when running in the console versus when running in a notebook, and the update_graph method has a different signature. More precisely, it doesn't take **kwargs. My use of update_graph looks like this:

bar.update_graph(plot, figsize=(10,5))

Full traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/app/lad/anomalies.py", line 120, in _train
    self.models[service].train(data_path=data_path, epochs=epochs, reporter=reporter)
  File "/app/lad/model.py", line 410, in train
    reporter=reporter)
  File "/app/lad/model.py", line 344, in train
    vis(mb,len_dataloader,epoch-start_epoch,i,[train_losses,val_losses])
  File "/app/lad/model.py", line 288, in vis
    bar.update_graph(plot, figsize=(10,5))
TypeError: update_graph() got an unexpected keyword argument 'figsize'

Support for JupyterLab

Hi, is fastprogress officially supporting Jupyter Lab?
For now, calling progress_bar doesn't show the bar:

image

If no, it would be good to integrate it to Jupyter Lab as more and more people are shifting to Lab.

AttributeError: 'NoneType' object has no attribute 'update' using Python 3.7

Issue #20 already described this problem for Python versions pre-3.7, but for me it also happens in Python 3.7. Even the history of issue #24 (which just bumped the version requirement) shows that the connection between the Python version and the bug is uncertain.

System info:

(click triangle on the left to expand/collapse)

=== Software === 
python        : 3.7.3
fastai        : 1.0.59
fastprogress  : 0.1.21
torch         : 1.3.0
nvidia driver : 418.40
torch cuda    : 10.1.243 / is **Not available** 

=== Hardware === 
nvidia gpus   : 1
Have 1 GPU(s), but torch can't use them (check nvidia driver) 

=== Environment === 
platform      : Linux-4.14.133-113.112.amzn2.x86_64-x86_64-with-Ubuntu-18.04-bionic
distro        : #1 SMP Tue Jul 30 18:29:50 UTC 2019
conda env     : python3.6
python        : /usr/bin/python3.7
sys.path      : 
/usr/lib/python37.zip
/usr/lib/python3.7
/usr/lib/python3.7/lib-dynload
/home/username/.local/lib/python3.7/site-packages
/home/username/.conda/envs/python3.7/lib/python3.7/site-packages
/usr/local/lib/python3.7/dist-packages
/usr/lib/python3/dist-packages
/opt/cloudera/parcels/CDH/lib/spark/python
/home/username/.ipython

Stack trace:

(click triangle on the left to expand/collapse)

/home/username/.local/lib/python3.7/site-packages/fastai/train.py in fit_one_cycle(learn, cyc_len, max_lr, moms, div_factor, pct_start, final_div, wd, callbacks, tot_epochs, start_epoch)
     21     callbacks.append(OneCycleScheduler(learn, max_lr, moms=moms, div_factor=div_factor, pct_start=pct_start,
     22                                        final_div=final_div, tot_epochs=tot_epochs, start_epoch=start_epoch))
---> 23     learn.fit(cyc_len, max_lr, wd=wd, callbacks=callbacks)
     24 
     25 def fit_fc(learn:Learner, tot_epochs:int=1, lr:float=defaults.lr,  moms:Tuple[float,float]=(0.95,0.85), start_pct:float=0.72,

/home/username/.local/lib/python3.7/site-packages/fastai/basic_train.py in fit(self, epochs, lr, wd, callbacks)
    198         else: self.opt.lr,self.opt.wd = lr,wd
    199         callbacks = [cb(self) for cb in self.callback_fns + listify(defaults.extra_callback_fns)] + listify(callbacks)
--> 200         fit(epochs, self, metrics=self.metrics, callbacks=self.callbacks+callbacks)
    201 
    202     def create_opt(self, lr:Floats, wd:Floats=0.)->None:

/home/username/.local/lib/python3.7/site-packages/fastai/basic_train.py in fit(epochs, learn, callbacks, metrics)
     97             cb_handler.set_dl(learn.data.train_dl)
     98             cb_handler.on_epoch_begin()
---> 99             for xb,yb in progress_bar(learn.data.train_dl, parent=pbar):
    100                 xb, yb = cb_handler.on_batch_begin(xb, yb)
    101                 loss = loss_batch(learn.model, xb, yb, learn.loss_func, learn.opt, cb_handler)

/home/username/.local/lib/python3.7/site-packages/fastprogress/fastprogress.py in __init__(self, gen, total, display, leave, parent, auto_update)
    157     def __init__(self, gen, total=None, display=True, leave=True, parent=None, auto_update=True):
    158         self.progress = html_progress_bar(0, len(gen) if total is None else total, "")
--> 159         super().__init__(gen, total, display, leave, parent, auto_update)
    160 
    161     def on_iter_begin(self):

/home/username/.local/lib/python3.7/site-packages/fastprogress/fastprogress.py in __init__(self, gen, total, display, leave, parent, auto_update)
     55         else:
     56             self.leave,self.display=False,False
---> 57             parent.add_child(self)
     58         self.comment = ''
     59         if not self.auto_update:

/home/username/.local/lib/python3.7/site-packages/fastprogress/fastprogress.py in add_child(self, child)
    207         self.child = child
    208         self.inner_dict['pb2'] = self.child.progress
--> 209         self.show()
    210 
    211     def show(self):

/home/username/.local/lib/python3.7/site-packages/fastprogress/fastprogress.py in show(self)
    214         to_show = [name for name in self.order if name in self.inner_dict.keys()]
    215         self.html_code = '\n'.join([self.inner_dict[n] for n in to_show])
--> 216         self.out.update(HTML(self.html_code))
    217 
    218     def write(self, line, table=False):

AttributeError: 'NoneType' object has no attribute 'update'

I may be mistaken, but it seems to me that:

  • self.out is only set in NBMasterBar.on_iter_begin, but NBMasterBar.show may try use it regardless.
  • NBMasterBar.show can be called by NBMasterBar.add_child, which happens from ProgressBar.__init__ as parent.add_child(self).

conversion of cuda tensors

I am getting an error at the end of a fastai training loop.

can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Seems a bit weird that pytorch does not just log a warning and do the conversion for you. However as they don't it would be useful to add ".cpu()" in the progress bar or earlier. This is my stack trace:

TypeError Traceback (most recent call last)
in
----> 1 learn.fit(1, lr=.01)

in fit(self, epochs, lr, callbacks)
8 callbacks = [cb(self) for cb in self.callback_fns] + listify(callbacks)
9 fit(epochs, self.model, self.loss_func, opt=self.opt, data=self.data, metrics=self.metrics,
---> 10 callbacks=self.callbacks+callbacks)
11
12 # create and fit model

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
87 except Exception as e:
88 exception = e
---> 89 raise e
90 finally: cb_handler.on_train_end(exception)
91

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/basic_train.py in fit(epochs, model, loss_func, opt, data, callbacks, metrics)
84 cb_handler=cb_handler, pbar=pbar)
85 else: val_loss=None
---> 86 if cb_handler.on_epoch_end(val_loss): break
87 except Exception as e:
88 exception = e

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/callback.py in on_epoch_end(self, val_loss)
250 met.on_epoch_end(**self.state_dict)
251 self.state_dict['last_metrics'].append(met.metric)
--> 252 return np.any(self('epoch_end', False))
253
254 def on_train_end(self, exception:Union[bool,Exception])->None:

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/callback.py in call(self, cb_name, call_mets, **kwargs)
185 "Call through to all of the CallbakHandler functions."
186 if call_mets: [getattr(met, f'on_{cb_name}')(**self.state_dict, **kwargs) for met in self.metrics]
--> 187 return [getattr(cb, f'on_{cb_name}')(**self.state_dict, **kwargs) for cb in self.callbacks]
188
189 def on_train_begin(self, epochs:int, pbar:PBar, metrics:MetricFuncList)->None:

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/callback.py in (.0)
185 "Call through to all of the CallbakHandler functions."
186 if call_mets: [getattr(met, f'on_{cb_name}')(**self.state_dict, **kwargs) for met in self.metrics]
--> 187 return [getattr(cb, f'on_{cb_name}')(**self.state_dict, **kwargs) for cb in self.callbacks]
188
189 def on_train_begin(self, epochs:int, pbar:PBar, metrics:MetricFuncList)->None:

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastai/train.py in on_epoch_end(self, n_epochs, last_metrics, **kwargs)
55 x_bounds = (0, (n_epochs - len(rec.nb_batches)) * rec.nb_batches[-1] + len(rec.losses))
56 y_bounds = (0, max((max(Tensor(rec.losses)), max(Tensor(rec.val_losses)))))
---> 57 rec.pbar.update_graph([(iters, rec.losses), (val_iter, rec.val_losses)], x_bounds, y_bounds)
58 return False
59

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/fastprogress/fastprogress.py in update_graph(self, graphs, x_bounds, y_bounds)
189 self.ax.legend(loc='upper right')
190 if x_bounds is not None: self.ax.set_xlim(*x_bounds)
--> 191 if y_bounds is not None: self.ax.set_ylim(*y_bounds)
192 with self.out:
193 clear_output(wait=True)

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/matplotlib/axes/_base.py in set_ylim(self, bottom, top, emit, auto, ymin, ymax)
3474 'bottom=%s, top=%s') % (bottom, top), stacklevel=2)
3475
-> 3476 bottom, top = mtransforms.nonsingular(bottom, top, increasing=False)
3477
3478 if self.get_yscale() == 'log':

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/matplotlib/transforms.py in nonsingular(vmin, vmax, expander, tiny, increasing)
2887 """
2888
-> 2889 if (not np.isfinite(vmin)) or (not np.isfinite(vmax)):
2890 return -expander, expander
2891

~/src/anaconda3/envs/fastai/lib/python3.6/site-packages/torch/tensor.py in array(self, dtype)
430 def array(self, dtype=None):
431 if dtype is None:
--> 432 return self.numpy()
433 else:
434 return self.numpy().astype(dtype, copy=False)

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Interactive demo for `fastprogress` code examples

Hello @fastai!

I've been trying fastprogress recently and found it really interesting. We are also thinking about adding it to our curriculum at https://rmotr.com/ (co-founder and teacher here). It improves the UX a lot while working with long running training processes.

While looking at the code examples in the README file I thought it would be great to provide some interactive demo that people can use to play with the library before committing to download and install it locally.

A demo is worth a thousand words 😉

I spent a few minutes compiling fastprogress examples into a Jupyter Notebook file, and adapted it in a way that we can open it with a small service we have at RMOTR to launch Jupyter environments online. Note that fastprogress (and other libraries like numpy) are already installed when the env is loaded, so people can start using it right away.

The result is what you can see in my fork of the repo (see the new "Demo" section):
https://github.com/martinzugnoni/fastprogress

Do you think that having such interactive demo would help people to know and use fastprogress?
Let's use this issue as a kick off to start a discussion. Nothing here is written in stone and we can change everything as you wish.

I hope you like it, and I truly appreciate any feedback.

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.