:py:mod:`mlair.model_modules.branched_input_networks` ===================================================== .. py:module:: mlair.model_modules.branched_input_networks Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: mlair.model_modules.branched_input_networks.BranchedInputCNN mlair.model_modules.branched_input_networks.BranchedInputRNN mlair.model_modules.branched_input_networks.BranchedInputFCN mlair.model_modules.branched_input_networks.BranchedInputUNet mlair.model_modules.branched_input_networks.BranchedInputResNet .. py:class:: BranchedInputCNN(input_shape: list, output_shape: list, layer_configuration: list, optimizer='adam', **kwargs) Bases: :py:obj:`mlair.model_modules.convolutional_networks.CNNfromConfig` A convolutional neural network with multiple input branches. .. py:method:: set_model(self) Abstract method to set model. .. py:method:: _get_layer_name(layer: tensorflow.keras.layers, layer_kwargs: Union[dict, None], pos: int, branch: int = None) :staticmethod: .. py:class:: BranchedInputRNN(input_shape, output_shape, *args, **kwargs) Bases: :py:obj:`mlair.model_modules.recurrent_networks.RNN` A recurrent neural network with multiple input branches. .. py:method:: set_model(self) Build the model. .. py:method:: 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 } :return: .. py:method:: _update_model_name(self, rnn_type) .. py:class:: 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: :py:obj:`mlair.AbstractModelClass` A fully connected network that uses multiple input branches that are combined by a concatenate layer. .. py:attribute:: _activation .. py:attribute:: _initializer .. py:attribute:: _optimizer .. py:attribute:: _regularizer .. py:attribute:: _requirements :annotation: = ['lr', 'beta_1', 'beta_2', 'epsilon', 'decay', 'amsgrad', 'momentum', 'nesterov', 'l1', 'l2'] .. py:attribute:: _dropout .. py:method:: _set_activation(self, activation) .. py:method:: _set_optimizer(self, optimizer, **kwargs) .. py:method:: _set_regularizer(self, regularizer, **kwargs) .. py:method:: _set_dropout(self, activation, dropout_rate) .. py:method:: _update_model_name(self) .. py:method:: set_model(self) Build the model. .. py:method:: 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 } :return: .. py:class:: BranchedInputUNet(input_shape, output_shape, layer_configuration: list, optimizer='adam', **kwargs) Bases: :py:obj:`mlair.model_modules.u_networks.UNet`, :py:obj:`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) ``` .. py:method:: set_model(self) Abstract method to set model. .. py:class:: BranchedInputResNet(input_shape: list, output_shape: list, layer_configuration: list, optimizer='adam', **kwargs) Bases: :py:obj:`mlair.model_modules.residual_networks.ResNet`, :py:obj:`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) ```