I am trying to add a test dataset to the databunch and getting the following error. There are 2 other questions (1, 2) similar to this with no clear answer.
Now, how can I add this test data to the data bunch and eventually run the trained model on test data? thanks
Code
data = (SegmentationItemList.from_folder(path/'train/images')
.split_by_rand_pct(0.3)
.label_from_func(get_y_fn, classes=codes)
.transform(get_transforms(), size=224, tfm_y=True)
.add_test((path/'test/images').ls(), label=None)
.databunch(path=Path('.'), bs=32)
.normalize(imagenet_stats))
Error
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
590 x = ds[0]
--> 591 try: x.apply_tfms(tfms, **kwargs)
592 except Exception as e:
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/core.py in apply_tfms(self, tfms, **kwargs)
187 "Subclass this method if you want to apply data augmentation with `tfms` to this `ItemBase`."
--> 188 if tfms: raise Exception(f"Not implemented: you can't apply transforms to this type of item ({self.__class__.__name__})")
189 return self
Exception: Not implemented: you can't apply transforms to this type of item (EmptyLabel)
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last)
<ipython-input-41-bd55d1f668b6> in <module>()
8 .label_from_func(get_y_fn, classes=codes)
9 .transform(get_transforms(), size=224, tfm_y=True)
---> 10 .add_test((path/'test/images').ls(), label=None)
11 .databunch(path=Path('.'), bs=32)
12 .normalize(imagenet_stats))
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/data_block.py in add_test(self, items, label, tfms, tfm_y)
560 elif isinstance(items, ItemList): items = self.valid.x.new(items.items, inner_df=items.inner_df).process()
561 else: items = self.valid.x.new(items).process()
--> 562 self.test = self.valid.new(items, labels, tfms=tfms, tfm_y=tfm_y)
563 return self
564
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/data_block.py in new(self, x, y, tfms, tfm_y, **kwargs)
627 tfms,tfm_y = ifnone(tfms, self.tfms),ifnone(tfm_y, self.tfm_y)
628 if isinstance(x, ItemList):
--> 629 return self.__class__(x, y, tfms=tfms, tfm_y=tfm_y, **self.tfmargs)
630 else:
631 return self.new(self.x.new(x, **kwargs), self.y.new(y, **kwargs), tfms=tfms, tfm_y=tfm_y).process()
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/data_block.py in __init__(self, x, y, tfms, tfm_y, **kwargs)
599 self.y.x = x
600 self.item=None
--> 601 self.transform(tfms, **kwargs)
602
603 def __len__(self)->int: return len(self.x) if self.item is None else 1
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/data_block.py in transform(self, tfms, tfm_y, **kwargs)
722 if tfm_y is None: tfm_y = self.tfm_y
723 tfms_y = None if tfms is None else list(filter(lambda t: getattr(t, 'use_on_y', True), listify(tfms)))
--> 724 if tfm_y: _check_kwargs(self.y, tfms_y, **kwargs)
725 self.tfms,self.tfmargs = tfms,kwargs
726 self.tfm_y,self.tfms_y,self.tfmargs_y = tfm_y,tfms_y,kwargs
/home/gbogu17/.local/lib/python3.7/site-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
591 try: x.apply_tfms(tfms, **kwargs)
592 except Exception as e:
--> 593 raise Exception(f"It's not possible to apply those transforms to your dataset:\n {e}")
594
595 class LabelList(Dataset):
Exception: It's not possible to apply those transforms to your dataset:
Not implemented: you can't apply transforms to this type of item (EmptyLabel)