Datasets don't have show_batch

Hello I am trying to port some of my code from fastai v1 to v2. Working through the Datablock tutorial I am having trouble with my Datablock not having show_batch methods when customising to my own use case. Has anyone come across something similar?

My Datablock & Dataset:

dblock = DataBlock(get_items = get_image_files,
                   get_y     = parent_label,
                   splitter  = RandomSplitter())

dsets = dblock.datasets("PlantVillage-Dataset/raw/color/")
dsets.train[0] # this works

The error I get when I try dsets.show_batch():

AttributeError                            Traceback (most recent call last)
<ipython-input-56-5a2f74730596> in <module>
----> 1 dsets.show_batch()

~/.pyenv/versions/3.7.8/envs/fastai/lib/python3.7/site-packages/fastai/data/ in __getattr__(self, k)
    315         return res if is_indexer(it) else list(zip(*res))
--> 317     def __getattr__(self,k): return gather_attrs(self, k, 'tls')
    318     def __dir__(self): return super().__dir__() + gather_attr_names(self, 'tls')
    319     def __len__(self): return len(self.tls[0])

~/.pyenv/versions/3.7.8/envs/fastai/lib/python3.7/site-packages/fastcore/ in gather_attrs(o, k, nm)
    163     att = getattr(o,nm)
    164     res = [t for t in att.attrgot(k) if t is not None]
--> 165     if not res: raise AttributeError(k)
    166     return res[0] if len(res)==1 else L(res)

AttributeError: show_batch

Hi, you have to create the DataLoaders first, this is where the items are batched together.

dls = dblock.dataloaders(path)

Also, I think you need to define your blocks before creating the dataloaders, so the images are actually opened and can be shown in the batch.

1 Like

Thanks this worked like a charm!