Shortcuts package

Submodules module, n_models, bs, model_builder, n_epochs, patience=None, loss_is_meaned=True, cb_partials=None, metric_partials=None, save_best=True, train_on_weights=True, bulk_move=True, start_model_id=0, excl_idxs=None, unique_trn_idxs=False, 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 a ModelBuilder on data provided by a FoldYielder, 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 a FoldYielder 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.

  • fy (FoldYielder) – FoldYielder interfacing ot training data

  • n_models (int) – number of models to train

  • bs (int) – batch size. Number of data points per iteration

  • model_builder (ModelBuilder) – ModelBuilder creating the networks to train

  • n_epochs (int) – maximum number of epochs for which to train

  • patience (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 true

  • cb_partials (Optional[List[Callable[[], Callback]]]) – optional list of functools.partial, each of which will instantiate a Callback when called

  • metric_partials (Optional[List[Callable[[], EvalMetric]]]) – optional list of functools.partial, each of which will a instantiate EvalMetric, used to compute additional metrics on validation data after each epoch. SaveBest and EarlyStopping will also act on the (first) metric set to main_metric instead of loss, except when another callback produces an alternative loss and model (like SWA).

  • save_best (bool) – if true, will save the best performing model as the final model, otherwise will save the model state as per the end of training. A copy of the best model will still be saved anyway.

  • train_on_weights (bool) – If weights are present in training data, whether to pass them to the loss function during training

  • bulk_move (bool) – if true, will optimise for speed by using more RAM and VRAM

  • start_model_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 trained

  • excl_idxs (Optional[List[int]]) – optional list of fold indeces to exclude from training and validation

  • unique_trn_idxs (bool) – if false, then fold indeces can be shared, e.g. if fy contains 10 folds and five models are requested, each model will be trained on 9 folds. if true, each model will every model will be trained on different folds, e.g. if fy contains 10 folds and five models are requested, each model will be trained on 2 folds and no same fold is used to train more than one model This is useful when the amount of training data exceeds the amount required to train a single model: it can be split into a large number of folds and a set of decorellated models trained.

  • live_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 results

  • plot_settings (PlotSettings) – PlotSettings class to control figure appearance

Return type

Tuple[List[Dict[str, float]], List[Dict[str, List[float]]], List[Dict[str, float]]]


  • 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 to Ensemble.

Module contents

Read the Docs v: latest
On Read the Docs
Project Home

Free document hosting provided by Read the Docs.


Access comprehensive developer and user documentation for LUMIN

View Docs


Get tutorials for beginner and advanced researchers demonstrating many of the features of LUMIN

View Tutorials