mlair.run_modules.model_setup

Model setup module.

Module Contents

Classes

ModelSetup

Set up the model.

Attributes

__author__

__date__

mlair.run_modules.model_setup.__author__ = Lukas Leufen, Felix Kleinert
mlair.run_modules.model_setup.__date__ = 2019-12-02
class mlair.run_modules.model_setup.ModelSetup

Bases: mlair.run_modules.run_environment.RunEnvironment

Set up the model.

Schedule of model setup:
  1. set channels (from variables dimension)

  2. build imported model

  3. plot model architecture

  4. load weights if enabled (e.g. to resume a training)

  5. set callbacks and checkpoint

  6. compile model

Required objects [scope] from data store:
  • experiment_path [.]

  • experiment_name [.]

  • train_model [.]

  • create_new_model [.]

  • generator [train]

  • model_class [.]

Optional objects
  • lr_decay [model]

Sets
  • channels [model]

  • model [model]

  • hist [model]

  • callbacks [model]

  • model_name [model]

  • all settings from model class like dropout_rate, initial_lr, and optimizer [model]

Creates
  • plot of model architecture <model_name>.pdf

_run(self)
_set_model_path(self)
_set_shapes(self)

Set input and output shapes from train collection.

_set_num_of_training_samples(self)

Set number of training samples - needed for example for Bayesian NNs

compile_model(self)

Compiles the keras model. Compile options are mandatory and have to be set by implementing set_compile() method in child class of AbstractModelClass.

_set_callbacks(self)

Set all callbacks for the training phase.

Add all callbacks with the .add_callback statement. Finally, the advanced model checkpoint is added.

copy_model(self)

Copy external model to internal experiment structure.

load_model(self)

Try to load model from disk or skip if not possible.

build_model(self)

Build model using input and output shapes from data store.

broadcast_custom_objects(self)

Broadcast custom objects to keras utils.

This method is very important, because it adds the model’s custom objects to the keras utils. By doing so, all custom objects can be treated as standard keras modules. Therefore, problems related to model or callback loading are solved.

get_model_settings(self)

Load all model settings and store in data store.

plot_model(self)

Plot model architecture as <model_name>.pdf.

report_model(self)
static _clean_name(orig_name: str)