FastAi GrandparentSplitter File Path

Viewed 122

I am trying to train a segmentation algorithm with FastAi. I have training and validation data in separate folders, so was planning on using GrandparentSplitter() but for some reason the validation set is empty.

My files are organised as below:

Path ---> train ---> images
                ---> masks
     ---> valid ---> images
                ---> masks

And this is how I set up my datablock and dataloader:

codes = np.array(['background', 'prostate'])

def label_func(x): return path/'train/masks'/f'{x.stem}_mask.png'

db = DataBlock(blocks=(ImageBlock(), MaskBlock(codes)),
              splitter=GrandparentSplitter(train_name='train', valid_name='valid'),
              get_items=get_image_files,
              get_y=label_func)

dls = db.dataloaders(path/'train/images', bs=1)
dls.show_batch()

I am assuming there is something wrong with how I organised the files.

1 Answers
Related