Skip to content

Data Generator

class DataGenerator

Class inherits from Keras Sequence base object, allows to use multiprocessing in .fit_generator.

DataGenerator is extended by these classes:

  • TrainDataGenerator

  • ValDataGenerator.

Attributes
  • samples: Dictionary of samples to generate data from.

  • image_dir: Path of image directory.

  • batch_size: Number of images per batch.

  • n_classes: Number of classes in dataset.

  • basenet_preprocess: Basenet specific preprocessing function.

  • img_load_dims: Dimensions that images get resized into when loaded.

  • train: If set to True samples are shuffled before each epoch and images are cropped once.

__init__

def __init__(samples, image_dir, batch_size, n_classes, basenet_preprocess, img_load_dims, train)

Inits DataGenerator object.

If train set True then samples are shuffled on init.

on_epoch_end

def on_epoch_end()

Method called at the end of every epoch.

If train set True then samples are shuffled.

__len__

def __len__()

Number of batches in the Sequence.

__getitem__

def __getitem__(index)

Gets batch at position index.

If train set True then images will be cropped by img_crop_dims.

class TrainDataGenerator

Class inherits from DataGenerator.

Per default images will be cropped and samples are shuffled before each epoch.

Attributes
  • samples: Dictionary of samples to generate data from.

  • image_dir: Path of image directory.

  • batch_size: Number of images per batch.

  • n_classes: Number of classes in dataset.

  • basenet_preprocess: Basenet specific preprocessing function.

  • img_load_dims: Dimensions that images get resized into when loaded (default (256, 256)).

  • img_crop_dims: Dimensions that images get resized into when loaded (default (224, 224)).

  • train: If set to True samples are shuffled before each epoch and images are cropped once (default True).

__init__

def __init__(samples, image_dir, batch_size, n_classes, basenet_preprocess, img_load_dims, img_crop_dims, train)

Inits TrainDataGenerator object.

Per default samples are shuffled on init.

class ValDataGenerator

Class inherits from DataGenerator.

Per default neither images are cropped nor samples are shuffled.

Attributes
  • samples: Dictionary of samples to generate data from.

  • image_dir: Path of image directory.

  • batch_size: Number of images per batch.

  • n_classes: Number of classes in dataset.

  • basenet_preprocess: Basenet specific preprocessing function.

  • img_load_dims: Dimensions that images get resized into when loaded (default (224, 224)).

  • train: If set to True samples are shuffled before each epoch and images are cropped once (default False).

__init__

def __init__(samples, image_dir, batch_size, n_classes, basenet_preprocess, img_load_dims, train)

Inits TrainDataGenerator object.