:py:mod:`data` ============== .. py:module:: data .. autoapi-nested-parse:: Loading images and other data from the file-system. Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: data.ImageLoader data.LoadImagesModule .. py:class:: ImageLoader Loads images from the file-system. .. py:attribute:: image_directory :annotation: :str The image directory to load images recursively from. .. py:attribute:: image_size :annotation: :Tuple[int, int] The size (height, width) to resize all images to. .. py:attribute:: extension :annotation: :str = jpg The extension (without a leading period) that all image files must match. .. py:attribute:: rgb :annotation: :bool = True When true, images are always loaded as RGB. when false, they are loaded as grayscale. .. py:attribute:: batch_size :annotation: :int = 16 How many images should be in a batch. .. py:attribute:: num_workers :annotation: :int = 1 The number of workers for the data-loader. .. py:method:: load_images(self) -> torch.utils.data.DataLoader Load all images recursively from a directory. :returns: a data-loader with all the images that match the extension recursively in a directory. .. py:method:: load_images_split_two(self, ratio_validation: float = 0.3) -> Tuple[torch.utils.data.DataLoader, torch.utils.data.DataLoader] Load all images recursively from a directory, and split into *training and validation batches*. :param ratio_validation: a number between 0 and 1 determining linearly how many elements belong in the validation set e.g. 0.4 would try and place 40% approximately of elements into the second partition. :returns: the loaded images, split into training and validation data respectively. .. py:method:: load_images_split_three(self, ratio_validation: float = 0.3, ratio_test: float = 0.2) -> Tuple[torch.utils.data.DataLoader, torch.utils.data.DataLoader, torch.utils.data.DataLoader] Load all images recursively from a directory, and split into *training, validation and test batches*. :param ratio_validation: a number between 0 and 1 determining linearly how many elements belong in the validation set e.g. 0.4 would try and place 40% approximately of elements into the second batch. :param ratio_test: a number between 0 and 1 determining linearly how many elements belong in the validation set e.g. 0.2 would try and place 20% approximately of elements into the third batch. :returns: the loaded images, split into training and validation data and test data respectively. .. py:class:: LoadImagesModule(image_directory: str, image_size: int, extension: str = 'jpg', rgb: bool = True, batch_size: int = 16, num_workers: int = 1, ratio_validation: float = 0.3, ratio_test: float = 0.2) Bases: :py:obj:`pytorch_lightning.LightningDataModule` A Lightning data-module for loading images recursively from a file-system directory. .. py:method:: prepare_data(self) -> None Overrides :class:`pl.LightningDataModule`. .. py:method:: setup(self, stage: Optional[pytorch_lightning.trainer.states.TrainerFn] = None) Overrides :class:`pl.LightningDataModule`. .. py:method:: train_dataloader(self) Overrides :class:`pl.LightningDataModule`. .. py:method:: val_dataloader(self) Overrides :class:`pl.LightningDataModule`. .. py:method:: test_dataloader(self) Overrides :class:`pl.LightningDataModule`. .. py:method:: predict_dataloader(self) Overrides :class:`pl.LightningDataModule`.