training

A simple set of functions that train with a curses display.

bpreveal.training.buildLosses(heads)

Given the output head specification (from the configuration JSON), build losses.

Parameters:

heads (dict) – The heads section from a configuration file.

Returns:

A tuple. The first element contains the losses, and the second contains the loss weights.

Return type:

tuple[list, list]

This method injects the \({\lambda}\) parameter used for the adaptive loss algorithm into the heads data structure. After this function is done, each head in heads will contain

a member called \(\tt INTERNAL\_\lambda{}\text{-}variable\). This is an actual TensorFlow

variable, and it is hooked in to the counts loss so that the adaptive loss callback (which also gets a copy of heads) can adjust it during training.

Returns a 2-tuple, structured so:

  1. A list of all the profile losses followed by all the counts losses:

    profLoss1, profLoss2, ... profLossN, countsLoss1, countsLoss2, ... countsLossN

  2. A list of all the loss weights.

    Since the counts loss weight is included in the actual loss function, the weights that are given to the Keras training routine are all ones for the counts. The profile loss weights are taken straight from your json. profileWeight1, profileWeight2, ... profileWeightN, 1, 1, ... 1

bpreveal.training.trainWithGenerators(model, config, inputLength, outputLength)

Load up the generators from your config file and train the model!

Parameters:
  • model (tensorflow.keras.Model) – A compiled Keras model.

  • config (dict) – The configuration JSON, AFTER you have injected config["heads"] with buildLosses.

  • inputLength (int) – The input length of your model.

  • outputLength (int) – The output length of your model.

Returns:

The history dictionary from the training.

Return type:

keras.callbacks.History

bpreveal.training.trainModel(model, trainBatchGen, valBatchGen, epochs, earlyStop, outputPrefix, plateauPatience, heads)

Constructs callbacks and actually runs the training loop.

Parameters:
  • model (tensorflow.keras.Model) – The compiled model to train.

  • trainBatchGen (H5BatchGenerator) – The batch generator for training samples.

  • valBatchGen (H5BatchGenerator) – The batch generator for validation samples.

  • epochs (int) – The maximum number of epochs to train for.

  • earlyStop (int) – How many epochs without validation loss improvement before we stop training?

  • outputPrefix (str) – Where would you like your model saved? (This is used by the checkpoint callback.)

  • plateauPatience (int) – How many epochs without validation loss improvement before we reduce the learning rate?

  • heads (list[dict]) – The heads from the configuration JSON, AFTER you have injected losses with buildLosses.

Returns:

The history dictionary generated by the Keras training function.

Return type:

keras.callbacks.History