Multiple crops of each image file in the dataset with fastai

23 Views Asked by At

I have a classification dataset of high resolution texture images stored as png files. These images have very different resolutions. I want to waste as little information as possible so what I would like to do is get multiple random cropping/resizing from each image.

In the following code I attempt to make a dataloader that reads a single image and produces 4 datapoints by cropping/resizing randomly.

data_block = DataBlock(
    blocks=(ImageBlock, CategoryBlock),
    get_x=ColReader('image_path'),
    get_y=ColReader('label'),
    splitter=RandomSplitter()
    item_tfms=[RandomResizedCrop(400)] * 4,
    batch_tfms=aug_transforms()
)
# Only get one image from the dataframe, hopefully a dataset of 4 images will be created
train = data_block.dataloaders(train_df.loc[2:3], bs=4)

But apparently item_tfms composes the items in the list. I thought of repeating the input index this but if possible I want a) to decode each png as few times as possible and b) to use as much of of the fastai infrastructure as possible.

What is the recommended/efficient way of doing this?

0

There are 0 best solutions below