Dog vs cat in datablock

Guys, It may be dumb question but stucked why its not working?

def label_func(f): return f[0].isupper()

pets = DataBlock(blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(),
get_y=label_func,
item_tfms=Resize(460),
batch_tfms=aug_transforms(size=224))
dls = pets.dataloaders(path)

Hey @Mukeshraj. It looks like an issue with your get_y function. I think you got confused with usage of fastai High level API and the mid level API approach of datablocks.

For get_y you should pass Dependent Variable, for this case it should be based of files name & if it starts with Capital letter it’s a Cat, else Dog. Making the below modification you can fix the issue:

def label_func(f): return Path(f).name[0].isupper()

pets = DataBlock(blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=RandomSplitter(),
get_y=label_func,
item_tfms=Resize(460),
batch_tfms=aug_transforms(size=224))
dls = pets.dataloaders(path)

Let me know if something is still not clear for you.

1 Like

Thank you very much for the help. It’s works fine.

1 Like