mlair.model_modules.probability_models

>>> MyCustomisedModel().model.compile(**kwargs) == MyCustomisedModel().compile(**kwargs)
True

Module Contents

Classes

MyUnetProb

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

MyCNNProb

Taken fromhttps://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6

VarDense

ProbTestModel

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

ProbTestModel2

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

ProbTestModel3

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

ProbTestModel4

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

ProbTestModelMixture

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

DenseVariationalCustom

Trying to implement a DensVar that can be stored:

Convolution2DReparameterizationCustom

Functions

prior_trainable(kernel_size, bias_size=0, dtype=None)

nll(y_true, y_pred)

This function should return the negative log-likelihood of each sample

posterior(kernel_size, bias_size, dtype=None)

prior(kernel_size, bias_size, dtype=None)

Attributes

__author__

__date__

tfd

tfb

tfpl

mylayer

mlair.model_modules.probability_models.__author__ = Felix Kleinert
mlair.model_modules.probability_models.__date__ = 2022-07-08
mlair.model_modules.probability_models.tfd
mlair.model_modules.probability_models.tfb
mlair.model_modules.probability_models.tfpl
class mlair.model_modules.probability_models.MyUnetProb(input_shape: list, output_shape: list, num_of_training_samples: int)

Bases: mlair.model_modules.AbstractModelClass

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function.

set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

static prior(kernel_size, bias_size, dtype=None)
static posterior(kernel_size, bias_size, dtype=None)
class mlair.model_modules.probability_models.MyCNNProb(input_shape: list, output_shape: list)

Bases: mlair.model_modules.AbstractModelClass

Taken fromhttps://towardsdatascience.com/uncertainty-in-deep-learning-bayesian-cnn-tensorflow-probability-758d7482bef6 and modified to our data

static loss_fn(y_true, y_pred)
static custom_normal_prior(dtype, shape, name, trainable, add_variable_fn)
static laplace_prior(dtype, shape, name, trainable, add_variable_fn)
static approximate_kl(q, p, q_tensor)
conv_reparameterization_layer(self, filters, kernel_size, activation)
set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

class mlair.model_modules.probability_models.VarDense(units, make_posterior_fn, make_prior_fn, kl_weight=None, kl_use_exact=False, activation=None, use_bias=True, activity_regularizer=None, **kwargs)

Bases: tensorflow.keras.layers.Layer

call(self, inputs)
get_config(self)
mlair.model_modules.probability_models.prior_trainable(kernel_size, bias_size=0, dtype=None)
class mlair.model_modules.probability_models.ProbTestModel(input_shape: list, output_shape: list)

Bases: mlair.model_modules.AbstractModelClass

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function.

set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

class mlair.model_modules.probability_models.ProbTestModel2(input_shape: list, output_shape: list)

Bases: mlair.model_modules.AbstractModelClass

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function.

set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

class mlair.model_modules.probability_models.ProbTestModel3(input_shape: list, output_shape: list)

Bases: mlair.model_modules.AbstractModelClass

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function.

set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

class mlair.model_modules.probability_models.ProbTestModel4(input_shape: list, output_shape: list)

Bases: mlair.model_modules.AbstractModelClass

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function.

set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

class mlair.model_modules.probability_models.ProbTestModelMixture(input_shape: list, output_shape: list)

Bases: mlair.model_modules.AbstractModelClass

The AbstractModelClass provides a unified skeleton for any model provided to the machine learning workflow.

The model can always be accessed by calling ModelClass.model or directly by an model method without parsing the model attribute name (e.g. ModelClass.model.compile -> ModelClass.compile). Beside the model, this class provides the corresponding loss function.

set_model(self)

Abstract method to set model.

set_compile_options(self)

This method only has to be defined in child class, when additional compile options should be used () (other options than optimizer and loss) Has to be set as dictionary: {‘optimizer’: None,

‘loss’: None, ‘metrics’: None, ‘loss_weights’: None, ‘sample_weight_mode’: None, ‘weighted_metrics’: None, ‘target_tensors’: None }

Returns

mlair.model_modules.probability_models.nll(y_true, y_pred)

This function should return the negative log-likelihood of each sample in y_true given the predicted distribution y_pred. If y_true is of shape [B, E] and y_pred has batch shape [B] and event_shape [E], the output should be a Tensor of shape [B].

mlair.model_modules.probability_models.posterior(kernel_size, bias_size, dtype=None)
mlair.model_modules.probability_models.prior(kernel_size, bias_size, dtype=None)
class mlair.model_modules.probability_models.DenseVariationalCustom

Bases: tfpl

Trying to implement a DensVar that can be stored: https://github.com/tensorflow/probability/commit/0ca065fb526b50ce38b68f7d5b803f02c78c8f16#

get_config(self)
class mlair.model_modules.probability_models.Convolution2DReparameterizationCustom

Bases: tfpl

get_config(self)
mlair.model_modules.probability_models.mylayer