src.model.deeplearn.handle.dl_training_handler

Classes

DLTrainingHandler([freeze_training])

Class to handle the training of deep learning models.

class src.model.deeplearn.handle.dl_training_handler.DLTrainingHandler(freeze_training=None)

Class to handle the training of deep learning models.

Variables:

freeze_training (dict or None) – The freeze training specification, if any.

__init__(freeze_training=None)
__call__(mh, X, y_rf, callbacks)

Run all the fit logic, including the pre-fit and post-fit stages.

Parameters:
  • X – The pre-processed input.

  • y_rf – The point-wise labels for each receptive field.

  • callbacks (list) – The callbacks to be executed during fit.

Returns:

The fit history (also assigned internally to mh.history).

pre_fit(mh, X, y_rf, callbacks)

The pre-fit logic. Typically, it involves creating and populating a cache map that can be used by the underlying architecture (through Architecture.prefit_logic_callback() and the post-fit logic.a

See DLTrainingHandler.__call__() for details about the input arguments.

Returns:

The fit cache map/dictionary.

Return type:

dict

fit(mh, X, y_rf, callbacks)

The fit-logic. Typically, it involves preparing the training data (e.g., building the corresponding sequencer) and fitting the model. The freeze training logic is also handled here, if any.

See DLTrainingHandler.__call__() for details about the input arguments.

Returns:

The training history of the model.

model_fit(mh, callbacks, input_X, input_y)

Call the fit method of the model.

Parameters:
  • mh (DLModelHandler) – The model handler.

  • callbacks – See DLTrainingHandler.__call__().

  • input_X – The input training data ready to be fed into the neural network.

  • input_y – The input training references ready to be fed into the neural network.

Returns:

The history object representing the concrete training process.

store_fit_backup(mh, X, y_rf)

Store the values of the receptive fields before any sequencing so they can be later restored in exactly the same order as received when calling the DLTrainingHandler.fit() method.

See DLTrainingHandler.fit() and DLTrainingHandler.restore_fit_backup().

Parameters:
  • mh (DLModelHandler) – The model handler.

  • X – The input data representing the receptive fields.

  • y_rf – The references labeling the receptive fields.

Returns:

The file where the backup is stored or None if no backup was stored.

Return type:

file or None

restore_fit_backup(mh, input_X, fit_backup)

Restore the values of the receptive fields after fitting the model to their original values, i.e., those saved by DLTrainingHandler.fit() and DLTrainingHandler.store_fit_backup().

Parameters:
Returns:

Nothing at all, but the values of the receptive fields at input_X are restored to their original order.

static check_architecture_needs_backup(mh)

Check whether the input receptive fields of the current architecture need to be restored after fitting (True) or not (False).

In general, some architectures (e.g., ConvAutoencPwiseClassif) need a backup of the receptive fields. At least when they are coupled with a input sequencer (see :class:.DLSequencer`).

Parameters:

mh (DLModelHandler) – The model handler.

Returns:

True if a backup of the input receptive fields is necessary. Otherwise, false.

Return type:

bool

static check_input_needs_backup(input_X)

Check whether the input receptive fields needs to be restored after fitting (True) or not (False).

In general, some sequencers (e.g., DLSequencer) need a backup of the receptive fields.

Parameters:

input_X (DLSequencer or list) – The input receptive fields.

Returns:

True if a backup of the input receptive fields is necessary. Otherwise, false.

Return type:

bool

post_fit(mh, X, y_rf, callbacks, fit_cache_map)

The post-fit logic. Typically, it involves digesting the cache map that was generated during the pre-fit logic and running some architecture-dependent logic (see Architecture.posfit_logic_callback())

See DLTrainingHandler.__call__() for details about the input arguments.

Returns:

Nothing at all.

prepare_freeze_training(mh)

Find the iterations at which the training process must be interrupted to apply freeze training-related operations.

Thin wrapper that delegates to DLFreezeTrainingExecutor. The mock model handler in FreezeTrainingTest only provides training_epochs; we therefore pass mh.arch.nn only when the handler actually has it (necessary to expand string layer-domain entries like "all").

Returns:

The iterations at which a freeze-training related operations must be applied before computing further training iterations. For example, [5, 10, 15, 20] means that the training process must be interrupted at epochs 5, 10, 15, and 20 to apply some operation related to freeze training. Also, the specification of the operations that must be carried out at each relevant epoch. Finally, the initial learning rates, when given.

Return type:

tuple of (list of int, list of dict, and list of float)

handle_round_robin_freezing(layers, interval, strategy)

Thin wrapper around DLFreezeTrainingExecutor.handle_round_robin_freezing().

handle_random_freezing(layers, interval, strategy)

Thin wrapper around DLFreezeTrainingExecutor.handle_random_freezing().