ffcv icon indicating copy to clipboard operation
ffcv copied to clipboard

How to load single channel (or 4 channel) images

Open tcapelle opened this issue 3 years ago • 1 comments

I am trying to load a dataset consisting of 1 channel images, and don't know how to do it. I have modified the loading to open them as grayscale:

def pil_loader_grayscale(path: str) -> Image.Image:
    return pil_loader(path, mode="L")

and the dataset accordingly:

my_dataset = torchvision.datasets.ImageFolder(root="path2data", loader=pil_loader_grayscale)

and then to write this down:

from ffcv.writer import DatasetWriter
from ffcv.fields import RGBImageField, IntField

# Your dataset (`torch.utils.data.Dataset`) of (image, label) pairs
write_path = 'ds.beton'

# Pass a type for each data field
writer = DatasetWriter(write_path, {
    # Tune options to optimize dataset size, throughput at train-time
    'image': RGBImageField(max_resolution=32),
    'label': IntField()
})

# Write dataset
writer.from_indexed_dataset(my_dataset)

but shouldn't I be using something different that the RGBImageField?

tcapelle avatar Sep 30 '22 16:09 tcapelle

Support for Grayscale images should be coming soon (#176)

andrewilyas avatar Feb 28 '23 22:02 andrewilyas