Skip to content

How to load single channel (or 4 channel) images #259

@tcapelle

Description

@tcapelle

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions