fastai / fastprogress

Simple and flexible progress bar for Jupyter Notebook and console
Apache License 2.0
1.09k stars 106 forks source link

AttributeError: 'NBProgressBar' object has no attribute 'start_t' #72

Open mazzingkaizer opened 4 years ago

mazzingkaizer commented 4 years ago

I meet error as follows: https://github.com/fastai/fastbook/blob/master/07_sizing_and_tta.ipynb I did also follows pip install -Uqq fastbook import fastbook fastbook.setup_book() from fastbook import *

But error occured as follows : preds,targs = learn.tta() accuracy(preds, targs).item()

epoch train_loss valid_loss accuracy time

AttributeError Traceback (most recent call last)

in ----> 1 preds,targs = learn.tta() 2 accuracy(preds, targs).item() /opt/conda/lib/python3.7/site-packages/fastai/learner.py in tta(self, ds_idx, dl, n, item_tfms, batch_tfms, beta, use_max) 566 if item_tfms is not None or batch_tfms is not None: dl = dl.new(after_item=item_tfms, after_batch=batch_tfms) 567 try: --> 568 self(_before_epoch) 569 with dl.dataset.set_split_idx(0), self.no_mbar(): 570 if hasattr(self,'progress'): self.progress.mbar = master_bar(list(range(n))) /opt/conda/lib/python3.7/site-packages/fastai/learner.py in __call__(self, event_name) 131 def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)] 132 --> 133 def __call__(self, event_name): L(event_name).map(self._call_one) 134 135 def _call_one(self, event_name): /opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in map(self, f, *args, **kwargs) 270 else f.format if isinstance(f,str) 271 else f.__getitem__) --> 272 return self._new(map(g, self)) 273 274 def filter(self, f, negate=False, **kwargs): /opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs) 216 @property 217 def _xtra(self): return None --> 218 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs) 219 def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None) 220 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) 197 def __call__(cls, x=None, *args, **kwargs): 198 if not args and not kwargs and x is not None and isinstance(x,cls): return x --> 199 return super().__call__(x, *args, **kwargs) 200 201 # Cell /opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in __init__(self, items, use_list, match, *rest) 207 if items is None: items = [] 208 if (use_list is not None) or not _is_array(items): --> 209 items = list(items) if use_list else _listify(items) 210 if match is not None: 211 if is_coll(match): match = len(match) /opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in _listify(o) 114 if isinstance(o, list): return o 115 if isinstance(o, str) or _is_array(o): return [o] --> 116 if is_iter(o): return list(o) 117 return [o] 118 /opt/conda/lib/python3.7/site-packages/fastcore/foundation.py in __call__(self, *args, **kwargs) 177 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i) 178 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:] --> 179 return self.fn(*fargs, **kwargs) 180 181 # Cell /opt/conda/lib/python3.7/site-packages/fastai/learner.py in _call_one(self, event_name) 135 def _call_one(self, event_name): 136 assert hasattr(event, event_name), event_name --> 137 [cb(event_name) for cb in sort_by_run(self.cbs)] 138 139 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state) /opt/conda/lib/python3.7/site-packages/fastai/learner.py in (.0) 135 def _call_one(self, event_name): 136 assert hasattr(event, event_name), event_name --> 137 [cb(event_name) for cb in sort_by_run(self.cbs)] 138 139 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state) /opt/conda/lib/python3.7/site-packages/fastai/callback/core.py in __call__(self, event_name) 42 (self.run_valid and not getattr(self, 'training', False))) 43 res = None ---> 44 if self.run and _run: res = getattr(self, event_name, noop)() 45 if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit 46 return res /opt/conda/lib/python3.7/site-packages/fastai/callback/progress.py in before_epoch(self) 21 22 def before_epoch(self): ---> 23 if getattr(self, 'mbar', False): self.mbar.update(self.epoch) 24 25 def before_train(self): self._launch_pbar() /opt/conda/lib/python3.7/site-packages/fastprogress/fastprogress.py in update(self, val) 92 yield o 93 ---> 94 def update(self, val): self.main_bar.update(val) 95 96 # Cell /opt/conda/lib/python3.7/site-packages/fastprogress/fastprogress.py in update(self, val) 57 elif val <= self.first_its or val >= self.last_v + self.wait_for or val >= self.total: 58 cur_t = time.time() ---> 59 avg_t = (cur_t - self.start_t) / val 60 self.wait_for = max(int(self.update_every / (avg_t+1e-8)),1) 61 self.pred_t = avg_t * self.total AttributeError: 'NBProgressBar' object has no attribute 'start_t' Please. fix it correctly or reply how to avoid these error.
kposborne commented 3 years ago

Encountered this issue as well. Not sure if the issue is with the fastprogress bar or in how it is used when learn.tta() is called, but I worked around it by doing this:

learn.remove_cb(ProgressCallback)

After that, it did not hit the error