Module delta.ml.train

Train neural networks.

Functions

def compile_model(model_fn, training_spec, resume_path=None)

Compile and check that the model is valid.

Parameters

model_fn : Callable[[], tensorflow.keras.model.Model]
Function to construct a keras Model.
training_spec : TrainingSpec
Trainnig parameters.
resume_path : str
File name to load initial model weights from.

Returns

tensorflow.keras.models.Model:
The compiled model, ready for training.
def train(model_fn, dataset: ImageryDataset, training_spec, resume_path=None, internal_model_extension='.h5')

Trains the specified model on a dataset according to a training specification.

Parameters

model_fn : Callable[[], tensorflow.keras.model.Model]
Function that constructs a model.
dataset : ImageryDataset
Dataset to train on.
training_spec : TrainingSpec
Training parameters.
resume_path : str
Optional file to load initial model weights from.

Returns

(tensorflow.keras.models.Model, History): The trained model and the training history.

Classes

class ContinueTrainingException (msg: str = None, completed_epochs: int = 0, recompile_model: bool = False, learning_rate: float = None)

Callbacks can raise this exception to modify the model, recompile, and continue training.

Parameters

msg : str
Optional error message.
completed_epochs : int
The number of epochs that have been finished. (resumes from the next epoch)
recompile_model : bool
If True, recompile the model. This is necessary if the model has been changed.
learning_rate : float
Optionally set the learning rate to the given value.
Expand source code
class ContinueTrainingException(Exception):
    """
    Callbacks can raise this exception to modify the model, recompile, and
    continue training.
    """
    def __init__(self, msg: str=None, completed_epochs: int=0,
                 recompile_model: bool=False, learning_rate: float=None):
        """
        Parameters
        ----------
        msg: str
            Optional error message.
        completed_epochs: int
            The number of epochs that have been finished. (resumes from the next epoch)
        recompile_model: bool
            If True, recompile the model. This is necessary if the model has been changed.
        learning_rate: float
            Optionally set the learning rate to the given value.
        """
        super().__init__(msg)
        self.completed_epochs = completed_epochs
        self.recompile_model = recompile_model
        self.learning_rate = learning_rate

Ancestors

  • builtins.Exception
  • builtins.BaseException
class DeltaLayer (trainable=True, name=None, dtype=None, dynamic=False, **kwargs)

Network layer class with extra features specific to DELTA.

Extentds tensorflow.keras.layers.Layer.

Expand source code
class DeltaLayer(Layer):
    """
    Network layer class with extra features specific to DELTA.

    Extentds `tensorflow.keras.layers.Layer`.
    """
    def callback(self): # pylint:disable=no-self-use
        """
        Override this method to make a layer automatically register
        a training callback.

        Returns
        -------
        tensorflow.keras.callbacks.Callback:
            The callback to register (or None).
        """
        return None

Ancestors

  • keras.src.engine.base_layer.Layer
  • tensorflow.python.module.module.Module
  • tensorflow.python.trackable.autotrackable.AutoTrackable
  • tensorflow.python.trackable.base.Trackable
  • keras.src.utils.version_utils.LayerVersionSelector

Subclasses

Methods

def callback(self)

Override this method to make a layer automatically register a training callback.

Returns

tensorflow.keras.callbacks.Callback:
The callback to register (or None).