Callbacks

Callbacks are a set of functions that can be applied at given stages of the training procedure. They can be used to get a view on internal states and statistics of the model during training. You can pass a list of callbacks to the train method of the Network class. Each callback has it’s own purpose make sure the read their documentation carefully.

class NeuralNetPy.callbacks.CSVLogger

Bases: Callback

Initializes a CSVLogger callback. This callback will log the training process in a CSV file.

Example
network.train(inputs, labels, 100, [NNP.callbacks.CSVLogger("logs.csv")])
class NeuralNetPy.callbacks.Callback

Bases: pybind11_object

This is the base class for all callbacks.

class NeuralNetPy.callbacks.EarlyStopping

Bases: Callback

Initializes an EarlyStopping callback. This callback will stop the training if the given metric doesn’t improve more than the given delta over a certain number of epochs (patience).

Parameters:
  • metric (str) – The metric to be monitored (Either LOSS or ACCURACY), defaults to LOSS

  • minDelta (float) – The minimum change in the monitored metric to be considered an improvement, defaults to 0.01

  • patience (int) – The number of epochs with no improvement after which training will be stopped, defaults to 0

Example
network.train(X, y, 100, [NNP.callbacks.EarlyStopping("loss", 0.01, 10)])
class NeuralNetPy.callbacks.ModelCheckpoint

Bases: Callback

ModelCheckpoint callback is used in parallel of training model.train to save a model (it’s parameters) in a checkpoint file at a given interval.

A couple of options provided by the callbacks are : * saveBestOnly If activated will save the “best” model (which is deduced automatically). * numEpochs Number of epoch intervals between checkpoints (only valid if saveBestOnly is False)

Params

param folderPath:

The path to the folder in which to save the checkpoints.

type folderPath:

str

param saveBestOnly:

Whether to save the best checkpoint or each one of them (default: True)

type saveBestOnly:

bool

param numEpochs:

The number of epochs interval between checkpoints

type numEpochs:

int

param verbose:

Verbose output (default: False)

type verbose:

bool