original_docstring: 
      Instantiates the U-Net architecture for semantic segmantation tasks.
  
      Args:
          num_classes: number of the segmentation classes.
          encoder_type: type of model to build upon. One of 'Default',
                        'DenseNet121', 'DenseNet169' 'EfficientNetB0',
                        'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3',
                        'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6',
                        'EfficientNetB7', 'MobileNet', 'MobileNetV2',
                        'ResNet50', 'ResNet101', 'ResNet152',
                        'ResNet50V2', 'ResNet101V2', 'ResNet152V2',
                        'VGG16', 'VGG19'. Default to 'Default'.
          input_shape: a tuple containing image height, width and channels
                        respectively. Default to (224,224,3).
          model_weights: (optional) link to pre-trained weights.
          num_blocks: (optional) number of encoder/decoder blocks.
          encoder_weights: (optional) pre-trained weights for encoder 
                           function. One of None (random initialization),
                           'imagenet' (pre-training on ImageNet),
                           or the path to the weights file to be loaded
          encoder_freeze: (optional) boolean to specify whether to train
                          encoder model parameters or not. Default is False.
          encoder_filters: (optional) a list containing filter sizes for each  
                           encoder and decoder blocks. Default to 
                           [32, 64, 128, 256, 512].
          decoder_type: (optional) one of 'transpose' (to use Conv2DTanspose 
                         layer for deconvolution  operation) or 'upsampling' 
                         (to use UpSampling2D layer for deconvolution  operation). 
                         Default to upsampling.
          num_decoder_block_conv_layers: (optional) number of convolution layers  
                                          for each decoder block (i.e. number of 
                                          Conv2D layers after upsampling layers). 
                                          Default is 1.
          decoder_activation: (optional) decoder activation name or function.
          decoder_use_skip_connection: (optional) one of True (to use skip 
                                       connections) or False (not to use skip 
                                       connections). Default to True.
          decoder_use_batchnorm: (optional) boolean to specify whether decoder
                                  layers should use BatchNormalization or not. 
                                  Default to True.
          decoder_dropout_rate: (optional) dropout rate. Float between 0 and 1.
          output_activation: (optional) activation for output layer.
                              Default is either 'sigmoid' or 'softmax' based on
                              the value of the 'num_classes' argument.
      Returns:
          model: keras unet segmentation model
      
      Research Paper/Documentation:
          https://arxiv.org/abs/1505.04597
          
      
docstring: Instantiates the U-Net architecture for semantic segmantation tasks.
docstring_tokens: Instantiates the U - Net architecture for semantic segmantation tasks .
code: def unet(num_classes,
           encoder_type='Default',
           input_shape=(224, 224, 3),
           model_weights=None,
           num_blocks=5,
           encoder_weights=None,
           encoder_freeze=False,
           encoder_filters=[32, 64, 128, 256, 512],
           decoder_type='upsampling',
           num_decoder_block_conv_layers=1,
           decoder_activation=None,
           decoder_use_skip_connection=True,
           decoder_use_batchnorm=True,
           decoder_dropout_rate=0,
           output_activation=None):
      """
      Instantiates the U-Net architecture for semantic segmantation tasks.
  
      Args:
          num_classes: number of the segmentation classes.
          encoder_type: type of model to build upon. One of 'Default',
                        'DenseNet121', 'DenseNet169' 'EfficientNetB0',
                        'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3',
                        'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6',
                        'EfficientNetB7', 'MobileNet', 'MobileNetV2',
                        'ResNet50', 'ResNet101', 'ResNet152',
                        'ResNet50V2', 'ResNet101V2', 'ResNet152V2',
                        'VGG16', 'VGG19'. Default to 'Default'.
          input_shape: a tuple containing image height, width and channels
                        respectively. Default to (224,224,3).
          model_weights: (optional) link to pre-trained weights.
          num_blocks: (optional) number of encoder/decoder blocks.
          encoder_weights: (optional) pre-trained weights for encoder 
                           function. One of None (random initialization),
                           'imagenet' (pre-training on ImageNet),
                           or the path to the weights file to be loaded
          encoder_freeze: (optional) boolean to specify whether to train
                          encoder model parameters or not. Default is False.
          encoder_filters: (optional) a list containing filter sizes for each  
                           encoder and decoder blocks. Default to 
                           [32, 64, 128, 256, 512].
          decoder_type: (optional) one of 'transpose' (to use Conv2DTanspose 
                         layer for deconvolution  operation) or 'upsampling' 
                         (to use UpSampling2D layer for deconvolution  operation). 
                         Default to upsampling.
          num_decoder_block_conv_layers: (optional) number of convolution layers  
                                          for each decoder block (i.e. number of 
                                          Conv2D layers after upsampling layers). 
                                          Default is 1.
          decoder_activation: (optional) decoder activation name or function.
          decoder_use_skip_connection: (optional) one of True (to use skip 
                                       connections) or False (not to use skip 
                                       connections). Default to True.
          decoder_use_batchnorm: (optional) boolean to specify whether decoder
                                  layers should use BatchNormalization or not. 
                                  Default to True.
          decoder_dropout_rate: (optional) dropout rate. Float between 0 and 1.
          output_activation: (optional) activation for output layer.
                              Default is either 'sigmoid' or 'softmax' based on
                              the value of the 'num_classes' argument.
      Returns:
          model: keras unet segmentation model
      
      Research Paper/Documentation:
          https://arxiv.org/abs/1505.04597
          
      """
      # -------------------------------------------------------------------------#
      # Validate and preprocess arguments
      # -------------------------------------------------------------------------#
      # 1. num_classes - check unet_decoder functon
      # 2. encoder_type - check unet_encoder functon
      # 3. input_shape 
      if not isinstance(input_shape, tuple):
          raise ValueError("The `input_shape` argument should a tuple containing "
                           "the image width, height and channels respectively.")
      if not len(input_shape) == 3:
          warnings.warn("The `input_shape` argument should be a tuple containg three "
                        "integer values for each of the image width, height and "
                        "channels respectively.")
      
      # 4. model_weights
      if not (model_weights in {None} or file_io.file_exists_v2(model_weights)):
          warnings.warn('The `model_weights` argument should either be '
                        '`None` (random initialization), '
                        'or the path to the weights file to be loaded.')
  
      # 5. num_blocks - check unet_encoder functon
      # 6. encoder_weights - check unet_encoder functon
      # 7. encoder_freeze - check unet_encoder functon
      # 8. encoder_filters - check unet_encoder functon
      # 9. decoder_type - check unet_decoder functon
      # 10. num_decoder_block_conv_layers - check unet_decoder functon
      # 11. decoder_activation - check unet_decoder functon
      # 12. decoder_use_skip_connection - check unet_decoder functon
      # 13. decoder_use_batchnorm - check unet_decoder functon
      # 14. decoder_dropout_rate - check unet_decoder functon
      # 15. output_activation - check unet_decoder functon
  
      # -------------------------------------------------------------------------#
      # Build Model
      # -------------------------------------------------------------------------#
      # 1. Get the encoder model, model output layer and skip connection layers
      input_tensor = Input(shape=(input_shape), name='input')    
      encoder_model, encoder_model_output_layer, skip_connection_layers = unet_encoder(
          encoder_type=encoder_type,
          input_tensor=input_tensor,
          encoder_weights=encoder_weights,
          encoder_freeze=encoder_freeze, 
          num_blocks=num_blocks, 
          encoder_filters=encoder_filters)
      
      # 2. Decoder blocks
      # Extend the model by adding the decoder blocks
      outputs = unet_decoder(
          num_classes=num_classes,
          decoder_input = encoder_model_output_layer,
          skip_connection_layers=skip_connection_layers,
          encoder_filters=encoder_filters,
          decoder_type=decoder_type,
          num_blocks=num_blocks,
          num_decoder_block_conv_layers=num_decoder_block_conv_layers,
          decoder_activation=decoder_activation,
          decoder_use_skip_connection=decoder_use_skip_connection,
          decoder_use_batchnorm=decoder_use_batchnorm,
          decoder_dropout_rate=decoder_dropout_rate,
          output_activation=output_activation)
  
      inputs = encoder_model.input
  
      ## Image Segmentation Model
      model = Model(inputs, outputs)
  
      return model
code_tokens: def unet ( num_classes , encoder_type = 'Default' , input_shape = ( 224 , 224 , 3 ) , model_weights = None , num_blocks = 5 , encoder_weights = None , encoder_freeze = False , encoder_filters = [ 32 , 64 , 128 , 256 , 512 ] , decoder_type = 'upsampling' , num_decoder_block_conv_layers = 1 , decoder_activation = None , decoder_use_skip_connection = True , decoder_use_batchnorm = True , decoder_dropout_rate = 0 , output_activation = None ) : if not isinstance ( input_shape , tuple ) : raise ValueError ( "The `input_shape` argument should a tuple containing " "the image width, height and channels respectively." ) if not len ( input_shape ) == 3 : warnings . warn ( "The `input_shape` argument should be a tuple containg three " "integer values for each of the image width, height and " "channels respectively." ) if not ( model_weights in { None } or file_io . file_exists_v2 ( model_weights ) ) : warnings . warn ( 'The `model_weights` argument should either be ' '`None` (random initialization), ' 'or the path to the weights file to be loaded.' ) input_tensor = Input ( shape = ( input_shape ) , name = 'input' ) encoder_model , encoder_model_output_layer , skip_connection_layers = unet_encoder ( encoder_type = encoder_type , input_tensor = input_tensor , encoder_weights = encoder_weights , encoder_freeze = encoder_freeze , num_blocks = num_blocks , encoder_filters = encoder_filters ) outputs = unet_decoder ( num_classes = num_classes , decoder_input = encoder_model_output_layer , skip_connection_layers = skip_connection_layers , encoder_filters = encoder_filters , decoder_type = decoder_type , num_blocks = num_blocks , num_decoder_block_conv_layers = num_decoder_block_conv_layers , decoder_activation = decoder_activation , decoder_use_skip_connection = decoder_use_skip_connection , decoder_use_batchnorm = decoder_use_batchnorm , decoder_dropout_rate = decoder_dropout_rate , output_activation = output_activation ) inputs = encoder_model . input model = Model ( inputs , outputs ) return model
short_docstring: Instantiates the U-Net architecture for semantic segmantation tasks.
short_docstring_tokens: Instantiates the U - Net architecture for semantic segmantation tasks .
comment: """
      Instantiates the U-Net architecture for semantic segmantation tasks.
  
      Args:
          num_classes: number of the segmentation classes.
          encoder_type: type of model to build upon. One of 'Default',
                        'DenseNet121', 'DenseNet169' 'EfficientNetB0',
                        'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3',
                        'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6',
                        'EfficientNetB7', 'MobileNet', 'MobileNetV2',
                        'ResNet50', 'ResNet101', 'ResNet152',
                        'ResNet50V2', 'ResNet101V2', 'ResNet152V2',
                        'VGG16', 'VGG19'. Default to 'Default'.
          input_shape: a tuple containing image height, width and channels
                        respectively. Default to (224,224,3).
          model_weights: (optional) link to pre-trained weights.
          num_blocks: (optional) number of encoder/decoder blocks.
          encoder_weights: (optional) pre-trained weights for encoder 
                           function. One of None (random initialization),
                           'imagenet' (pre-training on ImageNet),
                           or the path to the weights file to be loaded
          encoder_freeze: (optional) boolean to specify whether to train
                          encoder model parameters or not. Default is False.
          encoder_filters: (optional) a list containing filter sizes for each  
                           encoder and decoder blocks. Default to 
                           [32, 64, 128, 256, 512].
          decoder_type: (optional) one of 'transpose' (to use Conv2DTanspose 
                         layer for deconvolution  operation) or 'upsampling' 
                         (to use UpSampling2D layer for deconvolution  operation). 
                         Default to upsampling.
          num_decoder_block_conv_layers: (optional) number of convolution layers  
                                          for each decoder block (i.e. number of 
                                          Conv2D layers after upsampling layers). 
                                          Default is 1.
          decoder_activation: (optional) decoder activation name or function.
          decoder_use_skip_connection: (optional) one of True (to use skip 
                                       connections) or False (not to use skip 
                                       connections). Default to True.
          decoder_use_batchnorm: (optional) boolean to specify whether decoder
                                  layers should use BatchNormalization or not. 
                                  Default to True.
          decoder_dropout_rate: (optional) dropout rate. Float between 0 and 1.
          output_activation: (optional) activation for output layer.
                              Default is either 'sigmoid' or 'softmax' based on
                              the value of the 'num_classes' argument.
      Returns:
          model: keras unet segmentation model
      
      Research Paper/Documentation:
          https://arxiv.org/abs/1505.04597
          
      """$SEP$# -------------------------------------------------------------------------#$SEP$# Validate and preprocess arguments$SEP$# -------------------------------------------------------------------------#$SEP$# 1. num_classes - check unet_decoder functon$SEP$# 2. encoder_type - check unet_encoder functon$SEP$# 3. input_shape $SEP$# 4. model_weights$SEP$# 5. num_blocks - check unet_encoder functon$SEP$# 6. encoder_weights - check unet_encoder functon$SEP$# 7. encoder_freeze - check unet_encoder functon$SEP$# 8. encoder_filters - check unet_encoder functon$SEP$# 9. decoder_type - check unet_decoder functon$SEP$# 10. num_decoder_block_conv_layers - check unet_decoder functon$SEP$# 11. decoder_activation - check unet_decoder functon$SEP$# 12. decoder_use_skip_connection - check unet_decoder functon$SEP$# 13. decoder_use_batchnorm - check unet_decoder functon$SEP$# 14. decoder_dropout_rate - check unet_decoder functon$SEP$# 15. output_activation - check unet_decoder functon$SEP$# -------------------------------------------------------------------------#$SEP$# Build Model$SEP$# -------------------------------------------------------------------------#$SEP$# 1. Get the encoder model, model output layer and skip connection layers$SEP$# 2. Decoder blocks$SEP$# Extend the model by adding the decoder blocks$SEP$## Image Segmentation Model