When I try to use the validate
method of a loaded learner
I get the following below.
This can be replicated by running the camvid
example with fastai2 0.0.11
and after the first training section adding this line:
learn.validate(dl=dbunch, cbs=seg_accuracy)
EDIT:
dbunch = SegmentationDataLoaders.from_label_func(path, bs=8,
fnames = get_image_files(path/"images"),
label_func = lambda o: path/'labels'/f'{o.stem}_P{o.suffix}',
codes = np.loadtxt(path/'codes.txt', dtype=str),
batch_tfms=[*aug_transforms(size=(360,480)), Normalize.from_stats(*imagenet_stats)])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-18e6b46b04f7> in <module>()
----> 1 learn.validate(dl=dbunch, cbs=seg_accuracy)
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastai2/learner.py in validate(self, ds_idx, dl, cbs)
184 def validate(self, ds_idx=1, dl=None, cbs=None):
185 if dl is None: dl = self.dls[ds_idx]
--> 186 with self.added_cbs(cbs), self.no_logging(), self.no_mbar():
187 self(_before_epoch)
188 self._do_epoch_validate(ds_idx, dl)
~/anaconda3/envs/pytorch_p36/lib/python3.6/contextlib.py in __enter__(self)
79 def __enter__(self):
80 try:
---> 81 return next(self.gen)
82 except StopIteration:
83 raise RuntimeError("generator didn't yield") from None
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastai2/learner.py in added_cbs(self, cbs)
100 @contextmanager
101 def added_cbs(self, cbs):
--> 102 self.add_cbs(cbs)
103 yield
104 self.remove_cbs(cbs)
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastai2/learner.py in add_cbs(self, cbs)
83 def metrics(self,v): self._metrics = L(v).map(mk_metric)
84
---> 85 def add_cbs(self, cbs): L(cbs).map(self.add_cb)
86 def remove_cbs(self, cbs): L(cbs).map(self.remove_cb)
87 def add_cb(self, cb):
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastcore/foundation.py in map(self, f, *args, **kwargs)
360 else f.format if isinstance(f,str)
361 else f.__getitem__)
--> 362 return self._new(map(g, self))
363
364 def filter(self, f, negate=False, **kwargs):
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
313 @property
314 def _xtra(self): return None
--> 315 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
316 def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
317 def copy(self): return self._new(self.items.copy())
~/anaconda3/envs/pytorch_p36/lib/python3.6/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
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastcore/foundation.py in __init__(self, items, use_list, match, *rest)
304 if items is None: items = []
305 if (use_list is not None) or not _is_array(items):
--> 306 items = list(items) if use_list else _listify(items)
307 if match is not None:
308 if is_coll(match): match = len(match)
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastcore/foundation.py in _listify(o)
240 if isinstance(o, list): return o
241 if isinstance(o, str) or _is_array(o): return [o]
--> 242 if is_iter(o): return list(o)
243 return [o]
244
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastcore/foundation.py in __call__(self, *args, **kwargs)
206 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
207 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 208 return self.fn(*fargs, **kwargs)
209
210 # Cell
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/fastai2/learner.py in add_cb(self, cb)
86 def remove_cbs(self, cbs): L(cbs).map(self.remove_cb)
87 def add_cb(self, cb):
---> 88 old = getattr(self, cb.name, None)
89 assert not old or isinstance(old, type(cb)), f"self.{cb.name} already registered"
90 cb.learn = self
AttributeError: 'function' object has no attribute 'name'