train_models(fy, n_models, bs, model_builder, n_epochs, patience=None, loss_is_meaned=True, cb_partials=None, metric_partials=None, save_best=True, pred_cb=<class 'lumin.nn.callbacks.pred_handlers.PredHandler'>, 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>)¶
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
Modelis trained on N-1 folds, for a
FoldYielderwith 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.
int) – number of models to train
int) – batch size. Number of data points per iteration
int) – maximum number of epochs for which to train
int]) – if not None, sets the number of epochs or cycles to train without decrease in validation loss before ending training (early stopping)
bool) – if the batch loss value has been averaged over the number of elements in the batch, this should be true
EvalMetric]]]) – optional list of functools.partial, each of which will a instantiate
EvalMetric, used to compute additional metrics on validation data after each epoch.
EarlyStoppingwill also act on the (first) metric set to main_metric instead of loss, except when another callback produces an alternative loss and model (like
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.
PredHandler]) – pred_cb:
PredHandlercallback to determin how predictions are computed. Default simply returns the model predictions. Other uses could be e.g. running argmax on a multiclass classifier
bool) – If weights are present in training data, whether to pass them to the loss function during training
bool) – if true, will optimise for speed by using more RAM and VRAM
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
int]]) – optional list of fold indeces to exclude from training and validation
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.
bool) – whether or not to show any live feedback at all during training (slightly slows down training, but helps spot problems)
bool) – whether to only show live feedback for the first model trained (trade off between time and problem spotting)
bool) – whether to show extra information live feedback (further slows training)
bool) – whether to only show extra live feedback information for the first model trained (trade off between time and information)
Path) – path to to which to save model weights and results
- Return type
results list of validation losses and other eval_metrics results, ordered by model training. Can be used to create an
histories list of loss histories, ordered by model training