def get_dbunch_gray(size=160, bs=4, sh=0., workers=None):
source = Path("~/data/imagenette-160")
dblock = DataBlock(blocks=(ImageBlock(cls=PILImageBW), CategoryBlock),
splitter=GrandparentSplitter(valid_name='val'),
get_items=get_image_files, get_y=parent_label)
item_tfms=[RandomResizedCrop(size, min_scale=0.35), FlipItem(0.5)]
batch_tfms=RandomErasing(p=0.3, max_count=3, sh=sh) if sh else None
return dblock.databunch(source, path=source, bs=bs, num_workers=workers,
item_tfms=item_tfms, batch_tfms=batch_tfms)
dbunch_gray = get_dbunch_gray()
dbunch_gray.show_batch()
but the image shown is like the following,
it does not like grayscale image? What am I doing wrong?
The above code can be easily run in a jupyter notebook after downloading imagenette-160 dateset and change the path accordingly.
Thanks,