baby.training.flattener_trainer.FlattenerTrainer

class baby.training.flattener_trainer.FlattenerTrainer(save_dir: Path, stats_file: str, flattener_file: str)

Bases: object

Attributes
flattener

The last flattener saved to file.

stats

The last statistics computed, loaded from self.stats_file

Methods

fit([nbins, min_size, pad_frac, bud_max])

Optimise the parameters of the SegmentationFlattener based on previously computed statistics.

generate_flattener_stats(train_gen, val_gen, ...)

Generate overlap and erosion statistics for augmented data in input.

plot_stats([nbins])

Plot a histogram of cell overlap statistics of the training set.

__init__(save_dir: Path, stats_file: str, flattener_file: str)

Optimises the hyper-parameters for the SegmentationFlattener.

#TODO describe method for optimisation :param save_dir: the base directory in which to save outputs :param stats_file: the name of the file in which the stats are saved :param flattener_file: the name of the file defining the flattener

Methods

__init__(save_dir, stats_file, flattener_file)

Optimises the hyper-parameters for the SegmentationFlattener.

fit([nbins, min_size, pad_frac, bud_max])

Optimise the parameters of the SegmentationFlattener based on previously computed statistics.

generate_flattener_stats(train_gen, val_gen, ...)

Generate overlap and erosion statistics for augmented data in input.

plot_stats([nbins])

Plot a histogram of cell overlap statistics of the training set.

Attributes

flattener

The last flattener saved to file.

stats

The last statistics computed, loaded from self.stats_file

fit(nbins=30, min_size=10, pad_frac=0.03, bud_max=200)

Optimise the parameters of the SegmentationFlattener based on previously computed statistics.

# TODO define optimisation method

# TODO missing some unknown parameters :param nbins: :param min_size: the minimum size of a segmented object for it to be considered a cell. :param pad_frac: :param bud_max: the maximum size (in pixels) of cells considered buds. :return: None, saves the optimal parameters to the flattener file :raises: BadProcess if no statistics have been computed yet.

property flattener: SegmentationFlattening

The last flattener saved to file. :return: a segmentation flattener :raise: BadProcess, if no flattener has been assigned.

generate_flattener_stats(train_gen: ImageLabel, val_gen: ImageLabel, train_aug: Augmenter, val_aug: Augmenter, max_erode: int = 5)

Generate overlap and erosion statistics for augmented data in input.

Parameters
  • train_gen – the generator of training images and their labels

  • val_gen – the generator of validation images and their labels

  • train_aug – the augmenter to use for training images

  • val_aug – the augmenter to use for validation images

  • max_erode – the maximum allowed number of erosions used to

generate erosion values :return: None, saves results to self.stats_file

plot_stats(nbins=30)

Plot a histogram of cell overlap statistics of the training set.

# TODO describe what the plot means # TODO add an image as an example

Parameters

nbins – binning of data, passed to matplotlib.pyplot.hist2d

Returns

None, saves the resulting figure under `self.save_dir /

“flattener_stats.png”`

property stats: TrainValProperty

The last statistics computed, loaded from self.stats_file

Returns

The last training and validation statistics computed.

Raises

BadProcess error if the file does not exist.