utilities.segmentation_utils.flowreader module#
FlowGenerator is a wrapper around the keras ImageDataGenerator class.
- class FlowGenerator(image_path: str, mask_path: str, image_size: tuple[int, int], output_size: tuple[int, int], num_classes: int, shuffle: bool = True, batch_size: int = 2, preprocessing_enabled: bool = True, seed: int = 909, preprocessing_seed: int | None = None)[source]#
Bases:
object
Initializes the flow generator object, which can be used to read in images for semantic segmentation. Additionally, the reader can apply augmentation on the images, and one-hot encode them on the fly.
Note: in case the output is a column vector it has to be in the shape (x, 1)
Parameters#
- string image:
path to the image directory
- string mask:
path to the mask directory
- int batch_size:
batch size
- tuple image_size:
image size
- tuple output_size:
output size
- int num_classes:
number of classes
Keyword Arguments#
- bool shuffle:
whether to shuffle the dataset or not
- int batch_size:
batch size
- bool preprocessing_enabled:
whether to apply preprocessing or not
- int seed:
seed for flow from directory
- int preprocessing_seed:
seed for preprocessing, defaults to None
Raises#
- ValueError:
if the output size is not a tuple of length 2
- ValueError:
if the output size is not a square matrix or a column vector
- get_dataset_size() int [source]#
Returns the length of the dataset
Returns#
- returns int:
length of the dataset
- get_generator()[source]#
Returns the generator object
Returns#
- return ImageDataGenerator:
generator object
- preprocess(generator_zip)[source]#
Preprocessor function encapsulates both the image, and mask generator objects. Augments the images and masks and onehot encodes the masks
Parameters#
- tuple generator_zip:
tuple of image and mask generator
- int, optional state:
random state for reproducibility, defaults to None
Returns#
- return tuple(tf.Tensor,tf.Tensor):
generator batch of image and mask
- preprocessing_queue_image = None#
- preprocessing_queue_mask = None#
- preprocessing_seed = None#
- set_preprocessing_pipeline(preprocessing_queue_image: PreprocessorInterface, preprocessing_queue_mask: PreprocessorInterface) None [source]#
Sets the preprocessing pipeline
Parameters#
- PreprocessingQueue preprocessing_queue_image:
preprocessing queue for images
- PreprocessingQueue preprocessing_queue_mask:
preprocessing queue for masks
- class FlowGeneratorExperimental(image_path: str, mask_path: str, image_size: tuple[int, int], output_size: tuple[int, int], channel_mask: list[bool], num_classes: int, shuffle: bool = True, batch_size: int = 2, preprocessing_enabled: bool = True, seed: int = 909, preprocessing_seed: int | None = None, read_weights: bool = False, weights_path: str | None = None, preprocessing_queue_image=None, preprocessing_queue_mask=None, shuffle_counter=0)[source]#
Bases:
Sequence
Initializes the flow generator object, which can be used to read in images for semantic segmentation. Additionally, the reader can apply augmentation on the images, and one-hot encode them on the fly.
Note: in case the output is a column vector it has to be in the shape (x, 1) Note: this is an experimental version of the flow generator, which uses a custom implemented dataloader instead of the keras ImageDataGenerator #TODO: Instead of using direct paths, and arguments, reading heads should be used #TODO: as it reduces the number of arguments, and makes the code more readable and reduces #TODO: cupling
Parameters#
- string image:
path to the image directory
- string mask:
path to the mask directory
- int batch_size:
- tuple image_size:
specifies the size of the input image
- tuple output_size:
specifies the size of the output mask
- list[bool] channel_mask:
specifies which channels of the input image to use
- int num_classes:
number of classes in the output mask
Keyword Arguments#
- bool, optional shuffle:
whether to shuffle the dataset or not, defaults to True
- int batch_size:
specifies the number of images read in one batch, defaults to 2
- bool preprocessing_enabled:
whether to apply preprocessing or not, defaults to True
- int seed:
seed for flow from directory
- int preprocessing_seed:
seed for preprocessing, defaults to None
- bool read_weights:
whether to read the weights from the mask directory, defaults to False
Raises#
- ValueError:
if the names of the images and masks do not match
- ValueError:
if the output size is not a tuple of length 2
- ValueError:
if the output size is not a square matrix or a column vector
- set_mini_batch_size(batch_size: int) None [source]#
Function to set the appropriate minibatch size. Required to allign batch size in the reader with the model. Does not change the batch size of the reader.
Parameters#
- int batch_size:
the mini batch size
Raises#
- raises ValueError:
if the mini batch size is larger than the batch size
- raises ValueError:
if the batch size is not divisible by the mini batch size
- set_preprocessing_pipeline(preprocessing_queue_image: PreprocessorInterface, preprocessing_queue_mask: PreprocessorInterface) None [source]#
Sets the preprocessing pipeline
Parameters#
- PreprocessingQueue preprocessing_queue_image:
preprocessing queue for images
- PreprocessingQueue preprocessing_queue_mask:
preprocessing queue for masks