msdnet.train module

Module for training networks.

class msdnet.train.TrainAlgorithm[source]

Bases: abc.ABC

Base class implementing a training algorithm.

abstract step(n, dlist)[source]

Take a single algorithm step.

Parameters
abstract to_dict()[source]

Save algorithm state to dictionary

abstract load_dict(dct)[source]

Load algorithm state from dictionary

abstract classmethod from_dict(dct)[source]

Load algorithm from dictionary

classmethod from_file(fn)[source]

Load algorithm from file

to_file(fn)[source]

Save algorithm state to file

class msdnet.train.AdamAlgorithm(network, a=0.001, b1=0.9, b2=0.999, e=1e-08)[source]

Bases: msdnet.train.TrainAlgorithm

Implementation of the ADAM algorithm.

Parameters
  • networknetwork.Network to train with

  • a – ADAM parameter

  • b1 – ADAM parameter

  • b2 – ADAM parameter

  • e – ADAM parameter

step(n, dlist)[source]

Take a single algorithm step.

Parameters
to_dict()[source]

Save algorithm state to dictionary

load_dict(dct)[source]

Load algorithm state from dictionary

classmethod from_dict(dct)[source]

Load algorithm from dictionary

msdnet.train.restore_training(fn, netclass, trainclass, valclass, valdata, gpu=True)[source]

Restore training from file.

Parameters
Returns

network object, training algorithm object, and validation object

msdnet.train.train(network, trainalg, validation, dataprov, outputfile, val_every=None, loggers=None, stopcrit=inf, progress=False)[source]

Train network.

Parameters
  • networknetwork.Network to train with

  • trainalgTrainAlgorithm object that performs training.

  • validationvalidate.Validation object that performs validation.

  • dataprovdata.BatchProvider object that generates training batches.

  • outputfile – file to store trained network parameters in

  • val_every – (optional) number of training steps before each validation step

  • loggers – (optional) list of loggers.Logger objects to perform logging.

  • stopcric – (optional) number of validations steps without improvement before stopping training

  • progress – (optional) whether to show progress during training