lumin.nn.training package¶
Submodules¶
lumin.nn.training.fold_train module¶
lumin.nn.training.metric_logger module¶
lumin.nn.training.train module¶
-
lumin.nn.training.train.
train_models
(fy, n_models, bs, model_builder, n_epochs, patience=None, loss_is_meaned=True, cb_partials=None, eval_metrics=None, pred_cb=<class 'lumin.nn.callbacks.pred_handlers.PredHandler'>, train_on_weights=True, bulk_move=True, start_mode_id=0, live_fdbk=False, live_fdbk_first_only=False, live_fdbk_extra=True, live_fdbk_extra_first_only=False, savepath=Path('train_weights'), plot_settings=<lumin.plotting.plot_settings.PlotSettings object>)[source]¶ Main training method for
Model
. Trains a specified numer of models created by aModelBuilder
on data provided by aFoldYielder
, and saves them to savepath.Note, this does not return trained models, instead they are saved and must be loaded later. Instead this method returns results of model training. Each
Model
is trained on N-1 folds, for aFoldYielder
with N folds, and the remaining fold is used as validation data.Depending on the live_fdbk arguments, live plots of losses and other metrics may be shown during training, if running in Jupyter. Showing the live plot slightly slows down the training, but can help highlight problems without having to wait to the end. If not running in Jupyter, then losses are printed to the terminal.
Once training is finished, the state with the lowest validation loss is loaded, evaluated, and saved.
- Parameters
fy (
FoldYielder
) –FoldYielder
interfacing ot training datan_models (
int
) – number of models to trainbs (
int
) – batch size. Number of data points per iterationmodel_builder (
ModelBuilder
) –ModelBuilder
creating the networks to trainn_epochs (
int
) – maximum number of epochs for which to trainpatience (
Optional
[int
]) – if not None, sets the number of epochs or cycles to train without decrease in validation loss before ending training (early stopping)loss_is_meaned (
bool
) – if the batch loss value has been averaged over the number of elements in the batch, this should be truecb_partials (
Optional
[List
[partial
]]) – optional list of functools.partial, each of which will a instantiateCallback
when calledeval_metrics (
Optional
[Dict
[str
,EvalMetric
]]) – list of instantiatedEvalMetric
. At the end of training, validation data and model predictions will be passed to each, and the results printed and savedpred_cb (
Callable
[[],PredHandler
]) – pred_cb:PredHandler
callback to determin how predictions are computed. Default simply returns the model predictions. Other uses could be e.g. running argmax on a multiclass classifiertrain_on_weights (
bool
) – If weights are present in training data, whether to pass them to the loss function during trainingbulk_move (
bool
) – if true, will optimise for speed by using more RAM and VRAMstart_mode_id (
int
) – model ID at whcih to start training, i.e. if training was interupted, this can be set to resume training form the last model which was trainedlive_fdbk (
bool
) – whether or not to show any live feedback at all during training (slightly slows down training, but helps spot problems)live_fdbk_first_only (
bool
) – whether to only show live feedback for the first model trained (trade off between time and problem spotting)live_fdbk_extra (
bool
) – whether to show extra information live feedback (further slows training)live_fdbk_extra_first_only (
bool
) – whether to only show extra live feedback information for the first model trained (trade off between time and information)savepath (
Path
) – path to to which to save model weights and resultsplot_settings (
PlotSettings
) –PlotSettings
class to control figure appearance
- Return type
Tuple
[List
[Dict
[str
,float
]],List
[Dict
[str
,List
[float
]]],List
[Dict
[str
,float
]]]- Returns
results list of validation losses and other eval_metrics results, ordered by model training. Can be used to create an
Ensemble
.histories list of loss histories, ordered by model training
cycle_losses if an
AbsCyclicCallback
was passed, lists validation losses at the end of each cycle, ordered by model training. Can be passed toEnsemble
.