datasets

RGBImageDataset

class RGBImageDataset(directory, size=224, crop_noise=0.0, augment=None, files=None)

simple RGB image dataset that loads images from a directory. supports augmentations and various utility methods as well as batch indexing (from list or slice).

Images accessed with __getitem__ are read, resized, optionally augmented and finally transformed into float tensors in range [0,1].

Parameters
  • directory (str) – path to the directory to read images from. Homedir style paths are supported.

  • size (Union[int, Tuple[int, int]]) – integer or tuple size for image. If a ::attr::size is a single integer or a tuple of the same two values we will use hearth.vision.transforms.ResizeCrop for resizing and crop_noise will be passed. If a tuple of different sizes are passed for non-square inputs crop_noise will be ignored and we will simply resize to the requested size. Defaults to 224 (commonly used in imagenet etc).

  • crop_noise (float) – noise: for shifting the crop window along the longest dimension. Defaults to 0.0 (no noise).

  • augment (Optional[Callable[[Tensor], Tensor]]) – optional augmentation function which accepts a single image tensor of shape (C, W, H) of integers in range [0,255] returns augmented version of that image. Defaults to None (no augmentation).

  • files (Optional[Sequence[str]]) – If a sequence of filenames is provided here we will use them instead of scanning the directory. The filenames are assumed to exist in the directory. This can be useful when breaking up a train and validation set which share the same directory or when working with a subset of the data. Defaults to None (directoy will be scanned.)

directory: str
size: Union[int, Tuple[int, int]] = 224
crop_noise: float = 0.0
augment: Optional[Callable[[torch.Tensor], torch.Tensor]] = None
files: Optional[Sequence[str]] = None
ids()

yields a list of ids (filenames stripped of endings)

show_img(i, augment=True)

display the image at index i with optional augmentation applied