I want to create a dataloader with RGBA images. I have set convert_mode as ‘RGBA’ but still, batch contains images with three channels only. I’m using the following code -
dblock = DataBlock(blocks=(ImageBlock, MaskBlock),
splitter = RandomSplitter(valid_pct=0.1), # Random 10% as validation set
get_items=get_image_files,
get_y=get_msk,
)
dls = dblock.dataloaders(Path('images_with_alpha'), bs=1, num_workers=2, convert_mode='RGBA')
batch = dls.one_batch()
print(batch[0].shape)
It is giving shape ((1, 3, 400, 280) but I expect it to be (1, 4, 400, 280).
I solved this problem by using custom ImageBlock. Here’s the code -
class PILImageRGBA(PILImage): _show_args,_open_args = {'cmap':'Viridis'},{'mode': 'RGBA'} # Used for loading RGBA input images
dblock = DataBlock(blocks=(ImageBlock(cls=PILImageRGBA), MaskBlock),
splitter = RandomSplitter(valid_pct=0.1), # Random 10% as validation set
get_items=get_image_files,
get_y=get_msk,
)