ffcv
ffcv copied to clipboard
How to load single channel (or 4 channel) images
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?
Support for Grayscale images should be coming soon (#176)