das.utils

General utilities

class das.utils.LossHistory[source]

[summary]

Parameters

keras ([type]) – [description]

on_epoch_begin(epoch, logs)[source]

Called at the start of an epoch.

Subclasses should override for any actions to run. This function should only be called during TRAIN mode.

Parameters
  • epoch – Integer, index of epoch.

  • logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.

on_epoch_end(epoch, logs)[source]

Called at the end of an epoch.

Subclasses should override for any actions to run. This function should only be called during TRAIN mode.

Parameters
  • epoch – Integer, index of epoch.

  • logs

    Dict, metric results for this training epoch, and for the

    validation epoch if validation is performed. Validation result keys are prefixed with val_. For training epoch, the values of the

    Model’s metrics are returned. Example`{‘loss’: 0.2, ‘accuracy’:

    0.7}`.

on_train_begin(logs)[source]

Called at the beginning of training.

Subclasses should override for any actions to run.

Parameters

logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.

class das.utils.QtProgressCallback(nb_epochs, comms)[source]

Init the callback.

Parameters
  • nb_epochs ([type]) – number of training epochs

  • comms (tuple) – tuple of (multiprocessing.Queue, threading.Event) The queue is used to transmit progress updates to the GUI, the event is set in the GUI to stop training.

on_epoch_end(epoch, logs=None)[source]

Called at the end of an epoch.

Subclasses should override for any actions to run. This function should only be called during TRAIN mode.

Parameters
  • epoch – Integer, index of epoch.

  • logs

    Dict, metric results for this training epoch, and for the

    validation epoch if validation is performed. Validation result keys are prefixed with val_. For training epoch, the values of the

    Model’s metrics are returned. Example`{‘loss’: 0.2, ‘accuracy’:

    0.7}`.

on_predict_batch_end(batch, logs=None)[source]

Called at the end of a batch in predict methods.

Subclasses should override for any actions to run.

Note that if the steps_per_execution argument to compile in tf.keras.Model is set to N, this method will only be called every N batches.

Parameters
  • batch – Integer, index of batch within the current epoch.

  • logs – Dict. Aggregated metric results up until this batch.

on_test_batch_end(batch, logs=None)[source]

Called at the end of a batch in evaluate methods.

Also called at the end of a validation batch in the fit methods, if validation data is provided.

Subclasses should override for any actions to run.

Note that if the steps_per_execution argument to compile in tf.keras.Model is set to N, this method will only be called every N batches.

Parameters
  • batch – Integer, index of batch within the current epoch.

  • logs – Dict. Aggregated metric results up until this batch.

on_train_batch_end(batch, logs=None)[source]

Called at the end of a training batch in fit methods.

Subclasses should override for any actions to run.

Note that if the steps_per_execution argument to compile in tf.keras.Model is set to N, this method will only be called every N batches.

Parameters
  • batch – Integer, index of batch within the current epoch.

  • logs – Dict. Aggregated metric results up until this batch.

on_train_begin(logs=None)[source]

Called at the beginning of training.

Subclasses should override for any actions to run.

Parameters

logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.

on_train_end(logs=None)[source]

Called at the end of training.

Subclasses should override for any actions to run.

Parameters

logs – Dict. Currently the output of the last call to on_epoch_end() is passed to this argument for this method but that may change in the future.

das.utils.load_from(filename: str, datasets: List[str])[source]

Load datasets from h5 file.

Parameters
  • filename (str) –

  • datasets (List[str]) – Names of the datasets (=keys) to load

Returns

[description]

Return type

[type]

das.utils.load_model(file_trunk: str, model_dict: Dict[str, Callable], model_ext: str = '_model.h5', params_ext: str = '_params.yaml', compile: bool = True)[source]

Load model with weights.

First tries to load the full model directly using keras.models.load_model - this will likely fail for models with custom layers. Second, try to init model from parameters and then add weights…

Parameters
  • file_trunk (str) – [description]

  • model_dict (Dict[str, Callable) – [description]

  • model_ext (str, optional) – [description]. Defaults to ‘_weights.h5’.

  • params_ext (str, optional) – [description]. Defaults to ‘_params.yaml’.

  • compile (bool, optional) – [description]. Defaults to True.

Returns

keras.Model

das.utils.load_model_and_params(model_save_name, model_dict={'cnn': <function cnn>, 'cnn2D': <function cnn2D>, 'fcn': <function fcn>, 'fcn2D': <function fcn2D>, 'tcn': <function tcn>, 'tcn_multi': <function tcn_multi>, 'tcn_seq': <function tcn_seq>, 'tcn_small': <function tcn_small>, 'tcn_stft': <function tcn_stft>, 'tcn_tcn': <function tcn_tcn>}) Tuple[tensorflow.python.keras.engine.training.Model, Dict[str, Any]][source]

[summary]

Parameters
  • model_save_name ([type]) – [description]

  • model_dict ([type], optional) – [description]. Defaults to models.model_dict.

Returns

[description]

Return type

keras.Model, Dict[str, Any]

das.utils.load_model_from_params(file_trunk: str, model_dict: Dict[str, Callable], weights_ext: str = '_model.h5', params_ext: str = '_params.yaml', compile: bool = True)[source]

Init architecture from code and load model weights into it. Helps with model loading issues across TF versions.

Parameters
  • file_trunk (str) – [description]

  • models_dict ([type]) – [description]

  • weights_ext (str, optional) – [description]. Defaults to ‘_model.h5’ (use weights from model file).

  • params_ext (str, optional) – [description]. Defaults to ‘_params.yaml’.

  • compile (bool, optional) – [description]. Defaults to True.

Returns

keras.Model

das.utils.load_params(file_trunk: str, params_ext: str = '_params.yaml') Dict[str, Any][source]

Load model/training parameters from yaml

Parameters
  • file_trunk (str) – [description]

  • params_ext (strs, optional) – [description]. Defaults to ‘_params.yaml’.

Returns

Parameter dictionary

Return type

Dict[str, Any]

das.utils.save_params(params: Dict[str, Any], file_trunk: str, params_ext: str = '_params.yaml')[source]

Save model/training parameters to yaml.

Parameters
  • params (Dict[str]) – [description]

  • file_trunk (str) – [description]

  • params_ext (str, optional) – [description]. Defaults to ‘_params.yaml’.