evoaug_tf.evoaug#

Model (implemented in Tensorflow) demonstrating how to use augmentations during training.

Module Contents#

Classes#

RobustModel

Tensorflow keras.Model to specify how augmentation should be applied to a model

Functions#

augment_max_len(augment_list)

Determine whether insertions are applied to determine the insert_max,

class evoaug_tf.evoaug.RobustModel(model_func, input_shape=None, augment_list=[], max_augs_per_seq=2, hard_aug=False, finetune=False, inference_aug=False, **kwargs)#

Bases: tensorflow.keras.Model

Tensorflow keras.Model to specify how augmentation should be applied to a model

Parameters:
  • model (keras.Model) – Keras model.

  • augment_list (list) – List of data augmentations, each a callable class from augment.py Default is empty list – no augmentations.

  • max_augs_per_seq (int) – Maximum number of augmentations to apply to each sequence. Value is superceded by the number of augmentations in augment_list.

  • hard_aug (bool) – Flag to set a hard number of augmentations, otherwise the number of augmentations is set randomly up to max_augs_per_seq, default is True.

  • finetune (bool) – Flag to turn off augmentations during training, default is False.

  • inference_aug (bool) – Flag to turn on augmentations during inference, default is False.

build_model(input_shape)#
call(inputs, training=False)#
train_step(data)#
test_step(batch)#
predict_step(batch)#
_apply_augment(x)#

Apply augmentations to each sequence in batch, x.

_pad_end(x)#

Add random DNA padding of length insert_max to the end of each sequence in batch.

finetune_mode(optimizer=None, lr=None)#

Turn on finetune flag – no augmentations during training.

save_weights(filepath)#
load_weights(filepath)#
evoaug_tf.evoaug.augment_max_len(augment_list)#

Determine whether insertions are applied to determine the insert_max, which will be applied to pad other sequences with random DNA. :param augment_list: List of augmentations. :type augment_list: list

Returns:

Value for insert max.

Return type:

int