lfcnn.training.utils package
Submodules
lfcnn.training.utils.aux_losses_container module
A loss container used for auxiliary losses, for example within the GradientSimilarity training strategy.
- class lfcnn.training.utils.aux_losses_container.AuxLossesContainer(losses, output_names=None)[source]
Bases:
Container
A container class for auxiliary losses.
This is mostly analogous to keras LossesContainer, however without flattening the losses for the different outputs as we need to know which auxiliary loss belongs to which output and there may be a different number of auxiliary losses per output.
lfcnn.training.utils.constraints module
Some Constraint classes used for multi-task learning strategies.
- class lfcnn.training.utils.constraints.MinVal(min_value=1e-07)[source]
Bases:
Constraint
Constrains the weights to be larger than a specified min_value.
Within some multi-task strategies, this constraint is used to ensure that no loss weight is set to zero (or even negative) during the loss weight update.
- Parameters:
min_value (
float
) – Minimum value of weight.
lfcnn.training.utils.gradients module
Some utils for gradient calculations.
- lfcnn.training.utils.gradients.gradients_add(gradients_a: List[Tensor], gradients_b: List[Tensor]) List[Tensor]
Element-wise addition of list of gradients as for example obtained from GradientTape.gradient.
This calculate ignores None in the sense that 5 + None = 5.
- Return type:
List
[Tensor
]
- lfcnn.training.utils.gradients.gradients_reduce_sum(gradient_list: List[List[Tensor]]) List[Tensor]
Reduce a list of gradients by elemt-wise summation across the list index.
This differs from regular tf.reduce_sum in that summation is not performed within a single gradient but across gradients.
- Return type:
List
[Tensor
]
- lfcnn.training.utils.gradients.gradients_scalar_multiply(scalar: float, gradients: List[Tensor]) List[Tensor]
Element-wise scalar multiplication of list of gradients as for example obtained from GradientTape.gradient.
This calculate ignores None in the sense that 5*None = 5.
- Return type:
List
[Tensor
]
lfcnn.training.utils.initializer module
Custom initializer classes.
lfcnn.training.utils.regularizers module
Some Regularizer classes used for multi-task learning strategies.
- class lfcnn.training.utils.regularizers.Log(alpha=1.0)[source]
Bases:
Regularizer
A regularizer that applies natural logarithm regularization penalty. The regularization penalty is computed as: loss = alpha * reduce_sum(log(x))
For example, this is used in the MultiTaskUncertainty training strategy.
- Variables:
alpha – Float; regularization factor.
- get_config()[source]
Returns the config of the regularizer.
An regularizer config is a Python dictionary (serializable) containing all configuration parameters of the regularizer. The same regularizer can be reinstantiated later (without any saved state) from this configuration.
This method is optional if you are just training and executing models, exporting to and from SavedModels, or using weight checkpoints.
This method is required for Keras model_to_estimator, saving and loading models to HDF5 formats, Keras model cloning, some visualization utilities, and exporting models to and from JSON.
- Returns:
Python dictionary.
- class lfcnn.training.utils.regularizers.Sum(alpha=1.0)[source]
Bases:
Regularizer
A regularizer that applies Sum regularization penalty. The regularization penalty is computed as: loss = alpha * reduce_sum(x)
- Variables:
alpha – Float; regularization factor.
- get_config()[source]
Returns the config of the regularizer.
An regularizer config is a Python dictionary (serializable) containing all configuration parameters of the regularizer. The same regularizer can be reinstantiated later (without any saved state) from this configuration.
This method is optional if you are just training and executing models, exporting to and from SavedModels, or using weight checkpoints.
This method is required for Keras model_to_estimator, saving and loading models to HDF5 formats, Keras model cloning, some visualization utilities, and exporting models to and from JSON.
- Returns:
Python dictionary.
Module contents
The LFCNN training utils module.