Training

koogu.train(data_feeder, model_dir, data_settings, model_architecture, training_config, verbose=2, **kwargs)

Perform training and evaluation.

Parameters:
  • data_feeder – An instance of a BaseFeeder implementation (e.g., SpectralDataFeeder).

  • model_dir – Path to the directory into which the trained model and its supporting files will be written.

  • data_settings

    A Python dictionary containing -

    • audio_settings : a sub-dictionary specifying parameters considered in data pre-processing,

    • spec_settings : (optional) a sub-dictionary specifying parameters considered in data transformation (if any considered).

    These settings are not used during training, but must be specified so that they will be saved along with the trained model after training completes.

  • model_architecture – An instance of a BaseArchitecture implementation (e.g., DenseNet).

  • training_settings

    Training hyperparameters. A Python dictionary containing settings for defining the training process, controlling regularization, etc.

    Required fields

    • batch_size: (integer) Number of input samples from the dataset to combine in a single batch.

    • epochs: (integer) Number of epochs to perform the training for.

    Optional fields

    • optimizer: The optimizer to use during training. Must be a 2-element tuple specifying the name (string) of the optimizer and its parameters (a Python dictionary containing key-value pairs). Defaults to ['Adam', {}].

    • weighted_loss: (boolean; default: True) When enabled, loss function during training will be weighted based on the disparities in per-class training samples available.

    • l2_weight_decay: To enable, set to a reasonable value (e.g., 1e-4). Enabling it will add L2 regularization, with the specified decay.

    • learning_rate: Learning rate for training (default: 0.001). Can also specify dynamic rates, in one of two ways:

      • set this key to a static value, and specify both lr_change_at_epochs and lr_update_factors (see below), or

      • set this key to be a callable (e.g., function) which takes the current epoch number as input and returns the desired learning rate for the epoch.

    • lr_change_at_epochs: List of integers specifying the epochs at which the learning rate must be updated. If specifying this, learning_rate must be static.

    • lr_update_factors: List of integers (one element more than lr_change_at_epochs) specifying the decimation factor of the current learning rate at the set epochs. If specifying this, learning_rate must be static.

    • dropout_rate: Helps the model generalize better. Set to a small positive quantity (e.g., 0.05). Functionality is disabled by default.

    • epochs_between_evals: (optional; integer) Number of epochs to wait before performing another validation run. (default: 5)

  • verbose

    Level of information to display. Set to -

    0 - for no display
    1 - to display progress bars for each epoch
    2 - to display one-line summary per epoch (default)

  • random_seed – (optional) A seed (integer) used to initialize the psuedo-random number generator that makes setting randomized initial values for model parameters repeatable.

Returns:

A Python dictionary containing a record of the training history, including the “training” and “evaluation” accuracies and losses at each epoch.