micro_dl.input module
Submodules
micro_dl.input.dataset module
Dataset classes
- class micro_dl.input.dataset.BaseDataSet(tile_dir, input_fnames, target_fnames, dataset_config, batch_size, image_format='zyx')
Bases:
Sequence
Base class for input and target images
https://www.tensorflow.org/api_docs/python/tf/keras/utils/Sequence https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly.html https://github.com/aleju/imgaug
- get_steps_per_epoch()
Returns steps per epoch which is number of training samples per epoch divided by batch size.
- Return int steps_per_epoch:
Steps per epoch
- on_epoch_end()
Update indices and shuffle after each epoch
- micro_dl.input.dataset.apply_affine_transform(x, theta=0, tx=0, ty=0, shear=0, zx=1, zy=1, row_axis=1, col_axis=2, channel_axis=0, fill_mode='nearest', cval=0.0, order=1)
Applies an affine transformation specified by the parameters given. # Arguments
x: 3D numpy array - a 2D image with one or more channels. theta: Rotation angle in degrees. tx: Width shift. ty: Heigh shift. shear: Shear angle in degrees. zx: Zoom in x direction. zy: Zoom in y direction row_axis: Index of axis for rows (aka Y axis) in the input image.
Direction: left to right.
- col_axis: Index of axis for columns (aka X axis) in the input image.
Direction: top to bottom.
channel_axis: Index of axis for channels in the input image. fill_mode: Points outside the boundaries of the input
are filled according to the given mode (one of {‘constant’, ‘nearest’, ‘reflect’, ‘wrap’}).
- cval: Value used for points outside the boundaries
of the input if mode=’constant’.
order: int, order of interpolation
- # Returns
The transformed version of the input.
- micro_dl.input.dataset.transform_matrix_offset_center(matrix, x, y)
micro_dl.input.dataset_with_mask module
- class micro_dl.input.dataset_with_mask.DataSetWithMask(tile_dir, input_fnames, target_fnames, mask_fnames, dataset_config, batch_size, image_format='zyx')
Bases:
BaseDataSet
DataSet class that returns input, target images and sample weights
micro_dl.input.inference_dataset module
Dataset class / generator for inference only
- class micro_dl.input.inference_dataset.InferenceDataSet(image_dir, inference_config, dataset_config, network_config, split_col_ids, preprocess_config=None, image_format='zyx', mask_dir=None, flat_field_dir=None, crop2base=True)
Bases:
Sequence
Dataset class for model inference
- adjust_slice_indices()
Adjust slice indices if model is UNetStackTo2D or UNetStackToStack. These networks will have a depth > 1. Adjust inf_frames_meta only as we’ll need all the indices to load stack with depth > 1.
- get_iteration_meta()
Get the dataframe containing indices for one channel for inference iterations.
- Return pandas Dataframe inf_frames_meta:
Metadata and indices for first target channel
micro_dl.input.training_table module
- class micro_dl.input.training_table.BaseTrainingTable(df_metadata, input_channels, target_channels, split_by_column, split_ratio, mask_channels=None, random_seed=None)
Bases:
object
Generates the training table/info
- static split_train_val_test(sample_set, train_ratio, test_ratio, val_ratio=None, random_seed=None)
Generate indices for train, validation and test split
This can be achieved by using sklearn.model_selection.train_test_split twice… :-)
- Parameters:
sample_set (np.array/list) – A set of unique integer indices, for split column, not necessarily continuous values
train_ratio (float) – between 0 and 1, percent of samples to be used for training
test_ratio (float) – between 0 and 1, percent of samples to be used for test set
val_ratio (float) – between 0 and 1, percent of samples to be used for the validation set
random_seed (int) – between 0 and 2**32 - 1, random seed for train-val-test split
- Returns:
dict split_idx with keys [train, val, test] and values as lists
- Raises:
AssertionError: If ratios don’t add up to 1
- train_test_split()
Split into train-val-test
- Returns:
pd.DataFrame for train, val and test
Module contents
Module for Input functions