@muellerzr, I followed your new blog (thanks for putting that up, I have to read it multiple times
), and came up with this:
test_pipe = Pipeline([ColReader('fname', pref=str(path/'test_img') + os.path.sep), PILImage.create])
dls_over.valid_ds.tls[0].tfms = test_pipe
And, tested it with:
e = test_set(learn.dls.valid_ds, test_df)
And, it doesn’t fail.
But, when I now try to infer, I’m seeing this issue:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in _do_epoch_validate(self, ds_idx, dl)
184 self.dl = dl; self('begin_validate')
--> 185 with torch.no_grad(): self.all_batches()
186 except CancelValidException: self('after_cancel_validate')
20 frames
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in all_batches(self)
154 self.n_iter = len(self.dl)
--> 155 for o in enumerate(self.dl): self.one_batch(*o)
156
/usr/local/lib/python3.6/dist-packages/fastai2/data/load.py in __iter__(self)
97 self.before_iter()
---> 98 for b in _loaders[self.fake_l.num_workers==0](self.fake_l):
99 if self.device is not None: b = to_device(b, self.device)
/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in __next__(self)
362 def __next__(self):
--> 363 data = self._next_data()
364 self._num_yielded += 1
/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in _next_data(self)
988 del self._task_info[idx]
--> 989 return self._process_data(data)
990
/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in _process_data(self, data)
1013 if isinstance(data, ExceptionWrapper):
-> 1014 data.reraise()
1015 return data
/usr/local/lib/python3.6/dist-packages/torch/_utils.py in reraise(self)
394 msg = KeyErrorMessage(msg)
--> 395 raise self.exc_type(msg)
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 185, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 34, in fetch
data = next(self.dataset_iter)
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/load.py", line 107, in create_batches
yield from map(self.do_batch, self.chunkify(res))
File "/usr/local/lib/python3.6/dist-packages/fastcore/utils.py", line 299, in chunked
res = list(itertools.islice(it, chunk_sz))
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/load.py", line 120, in do_item
try: return self.after_item(self.create_item(s))
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/load.py", line 126, in create_item
def create_item(self, s): return next(self.it) if s is None else self.dataset[s]
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/core.py", line 293, in __getitem__
res = tuple([tl[it] for tl in self.tls])
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/core.py", line 293, in <listcomp>
res = tuple([tl[it] for tl in self.tls])
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/core.py", line 270, in __getitem__
return self._after_item(res) if is_indexer(idx) else res.map(self._after_item)
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/core.py", line 232, in _after_item
def _after_item(self, o): return self.tfms(o)
File "/usr/local/lib/python3.6/dist-packages/fastcore/transform.py", line 202, in __call__
def __call__(self, o): return compose_tfms(o, tfms=self.fs, split_idx=self.split_idx)
File "/usr/local/lib/python3.6/dist-packages/fastcore/transform.py", line 155, in compose_tfms
x = f(x, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/fastcore/transform.py", line 72, in __call__
def __call__(self, x, **kwargs): return self._call('encodes', x, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/fastcore/transform.py", line 82, in _call
return self._do_call(getattr(self, fn), x, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/fastcore/transform.py", line 88, in _do_call
return retain_type(f(x, **kwargs), x, ret)
File "/usr/local/lib/python3.6/dist-packages/fastcore/dispatch.py", line 99, in __call__
return f(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/fastai2/data/transforms.py", line 244, in encodes
def encodes(self, o): return TensorCategory(self.vocab.o2i[o])
KeyError: ''
During handling of the above exception, another exception occurred:
IndexError Traceback (most recent call last)
<ipython-input-93-eb42554961cb> in <module>()
----> 1 inp,preds, _ , preds_raw = learn.get_preds(dl=my_test_dl, with_input=True, with_decoded=True)
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in get_preds(self, ds_idx, dl, with_input, with_decoded, with_loss, act, inner, reorder, cbs, **kwargs)
234 for mgr in ctx_mgrs: stack.enter_context(mgr)
235 self(event.begin_epoch if inner else _before_epoch)
--> 236 self._do_epoch_validate(dl=dl)
237 self(event.after_epoch if inner else _after_epoch)
238 if act is None: act = getattr(self.loss_func, 'activation', noop)
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in _do_epoch_validate(self, ds_idx, dl)
185 with torch.no_grad(): self.all_batches()
186 except CancelValidException: self('after_cancel_validate')
--> 187 finally: self('after_validate')
188
189 def _end_cleanup(self):
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in __call__(self, event_name)
134 def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)]
135
--> 136 def __call__(self, event_name): L(event_name).map(self._call_one)
137 def _call_one(self, event_name):
138 assert hasattr(event, event_name)
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in map(self, f, *args, **kwargs)
381 else f.format if isinstance(f,str)
382 else f.__getitem__)
--> 383 return self._new(map(g, self))
384
385 def filter(self, f, negate=False, **kwargs):
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in _new(self, items, *args, **kwargs)
331 @property
332 def _xtra(self): return None
--> 333 def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
334 def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
335 def copy(self): return self._new(self.items.copy())
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __call__(cls, x, *args, **kwargs)
45 return x
46
---> 47 res = super().__call__(*((x,) + args), **kwargs)
48 res._newchk = 0
49 return res
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __init__(self, items, use_list, match, *rest)
322 if items is None: items = []
323 if (use_list is not None) or not _is_array(items):
--> 324 items = list(items) if use_list else _listify(items)
325 if match is not None:
326 if is_coll(match): match = len(match)
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in _listify(o)
258 if isinstance(o, list): return o
259 if isinstance(o, str) or _is_array(o): return [o]
--> 260 if is_iter(o): return list(o)
261 return [o]
262
/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __call__(self, *args, **kwargs)
224 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
225 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 226 return self.fn(*fargs, **kwargs)
227
228 # Cell
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in _call_one(self, event_name)
137 def _call_one(self, event_name):
138 assert hasattr(event, event_name)
--> 139 [cb(event_name) for cb in sort_by_run(self.cbs)]
140
141 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)
/usr/local/lib/python3.6/dist-packages/fastai2/learner.py in <listcomp>(.0)
137 def _call_one(self, event_name):
138 assert hasattr(event, event_name)
--> 139 [cb(event_name) for cb in sort_by_run(self.cbs)]
140
141 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)
/usr/local/lib/python3.6/dist-packages/fastai2/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
/usr/local/lib/python3.6/dist-packages/fastai2/callback/core.py in after_validate(self)
115 def after_validate(self):
116 "Concatenate all recorded tensors"
--> 117 if self.with_input: self.inputs = detuplify(to_concat(self.inputs, dim=self.concat_dim))
118 if not self.save_preds: self.preds = detuplify(to_concat(self.preds, dim=self.concat_dim))
119 if not self.save_targs: self.targets = detuplify(to_concat(self.targets, dim=self.concat_dim))
/usr/local/lib/python3.6/dist-packages/fastai2/torch_core.py in to_concat(xs, dim)
217 def to_concat(xs, dim=0):
218 "Concat the element in `xs` (recursively if they are tuples/lists of tensors)"
--> 219 if is_listy(xs[0]): return type(xs[0])([to_concat([x[i] for x in xs], dim=dim) for i in range_of(xs[0])])
220 if isinstance(xs[0],dict): return {k: to_concat([x[k] for x in xs], dim=dim) for k in xs[0].keys()}
221 #We may receives xs that are not concatenatable (inputs of a text classifier for instance),
IndexError: list index out of range