mlair.model_modules.branched_input_networks

Module Contents

Classes

BranchedInputCNN

A convolutional neural network with multiple input branches.

BranchedInputRNN

A recurrent neural network with multiple input branches.

BranchedInputFCN

A fully connected network that uses multiple input branches that are combined by a concatenate layer.

BranchedInputUNet

A U-net neural network with multiple input branches.

BranchedInputResNet

A convolutional neural network with multiple input branches and residual blocks (skip connections).

class mlair.model_modules.branched_input_networks.BranchedInputCNN(input_shape: list, output_shape: list, layer_configuration: list, optimizer='adam', **kwargs)

Bases: mlair.model_modules.convolutional_networks.CNNfromConfig

A convolutional neural network with multiple input branches.

set_model(self)

Abstract method to set model.

static _get_layer_name(layer: tensorflow.keras.layers, layer_kwargs: Union[dict, None], pos: int, branch: int = None)
class mlair.model_modules.branched_input_networks.BranchedInputRNN(input_shape, output_shape, *args, **kwargs)

Bases: mlair.model_modules.recurrent_networks.RNN

A recurrent neural network with multiple input branches.

set_model(self)

Build the 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

_update_model_name(self, rnn_type)
class mlair.model_modules.branched_input_networks.BranchedInputFCN(input_shape: list, output_shape: list, activation='relu', activation_output='linear', optimizer='adam', n_layer=1, n_hidden=10, regularizer=None, dropout=None, layer_configuration=None, batch_normalization=False, **kwargs)

Bases: mlair.AbstractModelClass

A fully connected network that uses multiple input branches that are combined by a concatenate layer.

_activation
_initializer
_optimizer
_regularizer
_requirements = ['lr', 'beta_1', 'beta_2', 'epsilon', 'decay', 'amsgrad', 'momentum', 'nesterov', 'l1', 'l2']
_dropout
_set_activation(self, activation)
_set_optimizer(self, optimizer, **kwargs)
_set_regularizer(self, regularizer, **kwargs)
_set_dropout(self, activation, dropout_rate)
_update_model_name(self)
set_model(self)

Build the 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.branched_input_networks.BranchedInputUNet(input_shape, output_shape, layer_configuration: list, optimizer='adam', **kwargs)

Bases: mlair.model_modules.u_networks.UNet, BranchedInputCNN

A U-net neural network with multiple input branches.

```python

input_shape = [(72,1,9),(72,1,9),] output_shape = [(4, )]

# model layer_configuration=[

# 1st block (down) {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 16, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 16, “padding”: “same”}, {“type”: “blocksave”}, {“type”: “MaxPooling2D”, “pool_size”: (2, 1), “strides”: (2, 1)},

# 2nd block (down) {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 32, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 32, “padding”: “same”}, {“type”: “blocksave”}, {“type”: “MaxPooling2D”, “pool_size”: (2, 1), “strides”: (2, 1)},

# 3rd block (down) {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 64, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 64, “padding”: “same”}, {“type”: “blocksave”}, {“type”: “MaxPooling2D”, “pool_size”: (2, 1), “strides”: (2, 1)},

# 4th block (final down) {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 128, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 128, “padding”: “same”},

# 5th block (up) {“type”: “Conv2DTranspose”, “activation”: “relu”, “kernel_size”: (2, 1), “filters”: 64, “strides”: (2, 1),

“padding”: “same”},

{“type”: “ConcatenateUNet”}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 64, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 64, “padding”: “same”},

# 6th block (up) {“type”: “Conv2DTranspose”, “activation”: “relu”, “kernel_size”: (2, 1), “filters”: 32, “strides”: (2, 1),

“padding”: “same”},

{“type”: “ConcatenateUNet”}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 32, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 32, “padding”: “same”},

# 7th block (up) {“type”: “Conv2DTranspose”, “activation”: “relu”, “kernel_size”: (2, 1), “filters”: 16, “strides”: (2, 1),

“padding”: “same”},

{“type”: “ConcatenateUNet”}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 16, “padding”: “same”}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 16, “padding”: “same”},

# Tail {“type”: “Concatenate”}, {“type”: “Flatten”}, {“type”: “Dense”, “units”: 128, “activation”: “relu”}

]

model = BranchedInputUNet(input_shape, output_shape, layer_configuration) ```

set_model(self)

Abstract method to set model.

class mlair.model_modules.branched_input_networks.BranchedInputResNet(input_shape: list, output_shape: list, layer_configuration: list, optimizer='adam', **kwargs)

Bases: mlair.model_modules.residual_networks.ResNet, BranchedInputCNN

A convolutional neural network with multiple input branches and residual blocks (skip connections).

```python input_shape = [(65,1,9), (65,1,9)] output_shape = [(4, )]

# model layer_configuration=[

{“type”: “Conv2D”, “activation”: “relu”, “kernel_size”: (7, 1), “filters”: 32, “padding”: “same”}, {“type”: “MaxPooling2D”, “pool_size”: (2, 1), “strides”: (2, 1)}, {“type”: “residual_block”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 32, “strides”: (1, 1), “kernel_regularizer”: “l2”}, {“type”: “residual_block”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 32, “strides”: (1, 1), “kernel_regularizer”: “l2”}, {“type”: “residual_block”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 64, “strides”: (1, 1), “kernel_regularizer”: “l2”, “use_1x1conv”: True}, {“type”: “residual_block”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 64, “strides”: (1, 1), “kernel_regularizer”: “l2”}, {“type”: “residual_block”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 128, “strides”: (1, 1), “kernel_regularizer”: “l2”, “use_1x1conv”: True}, {“type”: “residual_block”, “activation”: “relu”, “kernel_size”: (3, 1), “filters”: 128, “strides”: (1, 1), “kernel_regularizer”: “l2”}, {“type”: “MaxPooling2D”, “pool_size”: (2, 1), “strides”: (2, 1)}, {“type”: “Dropout”, “rate”: 0.25}, {“type”: “Flatten”}, {“type”: “Concatenate”}, {“type”: “Dense”, “units”: 128, “activation”: “relu”}

]

model = BranchedInputResNet(input_shape, output_shape, layer_configuration) ```