original_docstring: 
      Instantiates  encoder architecture for the U-Net segmmantation model.
  
      Args:
          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 encoder type is  'Default'.
          input_tensor: a tensorflow tensor input of a tuple containg image width,
                        height and channels respectively.
          encoder_weights: One of `None` (random initialization), `imagenet`,
                           or the path to the weights file to be loaded.
                           Default to None.
          encoder_freeze: Boolean Specifying whether to train encoder parameters
                          or not. Default to False.
          num_blocks: number of blocks to use for each encoder. Default to 5.
          encoder_filters: a list or tuple containing the number of filters to 
                           use for each encoder block. Default to 
                           [32, 64, 128, 256, 512].
      Returns:
          encoder_model: keras model
          encoder_model_output: Encoder model output.
          skip_connection_layers: Skip connection layers/encoder block outputs 
                                  before pooling.
      
docstring: Instantiates  encoder architecture for the U-Net segmmantation model.
docstring_tokens: Instantiates encoder architecture for the U - Net segmmantation model .
code: def unet_encoder(encoder_type='Default',
                   input_tensor=None,
                   encoder_weights=None,
                   encoder_freeze=False,
                   num_blocks=5,
                   encoder_filters=[32, 64, 128, 256, 512]):
      """
      Instantiates  encoder architecture for the U-Net segmmantation model.
  
      Args:
          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 encoder type is  'Default'.
          input_tensor: a tensorflow tensor input of a tuple containg image width,
                        height and channels respectively.
          encoder_weights: One of `None` (random initialization), `imagenet`,
                           or the path to the weights file to be loaded.
                           Default to None.
          encoder_freeze: Boolean Specifying whether to train encoder parameters
                          or not. Default to False.
          num_blocks: number of blocks to use for each encoder. Default to 5.
          encoder_filters: a list or tuple containing the number of filters to 
                           use for each encoder block. Default to 
                           [32, 64, 128, 256, 512].
      Returns:
          encoder_model: keras model
          encoder_model_output: Encoder model output.
          skip_connection_layers: Skip connection layers/encoder block outputs 
                                  before pooling.
      """
      #------------------------------------------------------------------------------#
      # Validate and preprocess arguments
      #------------------------------------------------------------------------------#
      # 1. encoder_type
      if encoder_type.lower() != 'default':
          if not encoder_type in encoder_models:
              raise ValueError("The `encoder_type` argument is not not properly defined. "
                          "Kindly use one of the following encoder names: 'Default', "
                          "'DenseNet121', 'DenseNet169', 'DenseNet201', 'EfficientNetB0', "
                          "'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3', "
                          "'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6', "
                          "'EfficientNetB67', 'MobileNet', 'MobileNetV2', 'ResNet50', "
                          "'ResNet101', 'ResNet152', 'ResNet50V2', 'ResNet101V2', "
                          "'ResNet152V2', 'VGG16', 'VGG19'")
  
      # 2. encoder_weights
      if encoder_type.lower() == 'default':
          if not (encoder_weights in {None} or 
                  file_io.file_exists_v2(encoder_weights)):
              warnings.warn('Ensure the `encoder_weights` argument is either '
                            '`None` (random initialization), '
                            'or the path to the weights file to be loaded. ')
      else:
          if not (encoder_weights in {'imagenet', None} or 
                  file_io.file_exists_v2(encoder_weights)):
              warnings.warn('The `encoder_weights` argument should be either '
                            '`None` (random initialization), `imagenet` '
                            '(pre-training on ImageNet), or the path to the '
                            'weights file to be loaded.')
  
      # 3. encoder_freeze
      if not isinstance(encoder_freeze, bool):
          raise ValueError("The `encoder_freeze` argument should either be True or "
                           "False.")
  
      # 4. num_blocks
      if not isinstance(num_blocks, int):
          raise ValueError('The `num_blocks` argument should be integer')
      elif num_blocks <= 0:
          raise ValueError('The `num_blocks` argument cannot be less than or equal to '
                           'zero')
  
      # 5. encoder_filters
      if not (isinstance(encoder_filters, tuple) or isinstance(encoder_filters, list)):
          raise ValueError('The `encoder_filters` argument should be a list of tuple.')
      elif len(encoder_filters) <= 0:
          raise ValueError('The `encoder_filters` argument cannot be an empty list.')
      elif len(encoder_filters) < num_blocks:
          raise ValueError('The items of the `encoder_filters` argument cannot be less '
                           'than the `num_blocks` argument.')
          
      #--------------------------------------------------------------------------#
      # Build the encoding blocks from the arguments specified
      #--------------------------------------------------------------------------#
      #--------------------------------------------------------------------------#
      # 1. Default encoding blocks
      #--------------------------------------------------------------------------#
      if encoder_type.lower() == 'default':
          x = input_tensor
          kernel_size = 3
          pool_size = 2
          skip_connection_layers = []
  
          # Design the model
          for filter_id in range(num_blocks):
              num_filters = encoder_filters[filter_id]
              x = convolution_block(x,
                                    num_filters=num_filters,
                                    kernel_size=kernel_size,
                                    dilation_rate=1,
                                    padding="same",
                                    use_bias=False,
                                    use_batchnorm=True,
                                    activation='relu')
  
              x = convolution_block(x,
                                    num_filters=num_filters,
                                    kernel_size=kernel_size,
                                    dilation_rate=1,
                                    padding="same",
                                    use_bias=False,
                                    use_batchnorm=True,
                                    activation='relu')
  
              # save block output layer before pooling
              skip_connection_layers.append(x)
  
              x = MaxPooling2D((pool_size, pool_size))(x)
  
          encoder_model_output = x
  
          # Create model
          encoder_model = Model(input_tensor, encoder_model_output)
  
      #--------------------------------------------------------------------------#
      # 2. Pretrained model encoding blocks
      #--------------------------------------------------------------------------#
      else:
          encoder_model = get_encoder_model(encoder_type,
                                            input_tensor,
                                            encoder_weights)
          skip_connection_layers = get_skip_connection_layers(encoder_type,
                                                              encoder_model)
          encoder_model_output = get_encoder_model_output_layer(encoder_type,
                                                                encoder_model,
                                                                num_blocks)
  
      # Make the model parameters trainable or non trainable
      encoder_model.trainable = not(encoder_freeze)
  
      return encoder_model, encoder_model_output, skip_connection_layers
code_tokens: def unet_encoder ( encoder_type = 'Default' , input_tensor = None , encoder_weights = None , encoder_freeze = False , num_blocks = 5 , encoder_filters = [ 32 , 64 , 128 , 256 , 512 ] ) : if encoder_type . lower ( ) != 'default' : if not encoder_type in encoder_models : raise ValueError ( "The `encoder_type` argument is not not properly defined. " "Kindly use one of the following encoder names: 'Default', " "'DenseNet121', 'DenseNet169', 'DenseNet201', 'EfficientNetB0', " "'EfficientNetB1', 'EfficientNetB2', 'EfficientNetB3', " "'EfficientNetB4', 'EfficientNetB5', 'EfficientNetB6', " "'EfficientNetB67', 'MobileNet', 'MobileNetV2', 'ResNet50', " "'ResNet101', 'ResNet152', 'ResNet50V2', 'ResNet101V2', " "'ResNet152V2', 'VGG16', 'VGG19'" ) if encoder_type . lower ( ) == 'default' : if not ( encoder_weights in { None } or file_io . file_exists_v2 ( encoder_weights ) ) : warnings . warn ( 'Ensure the `encoder_weights` argument is either ' '`None` (random initialization), ' 'or the path to the weights file to be loaded. ' ) else : if not ( encoder_weights in { 'imagenet' , None } or file_io . file_exists_v2 ( encoder_weights ) ) : warnings . warn ( 'The `encoder_weights` argument should be either ' '`None` (random initialization), `imagenet` ' '(pre-training on ImageNet), or the path to the ' 'weights file to be loaded.' ) if not isinstance ( encoder_freeze , bool ) : raise ValueError ( "The `encoder_freeze` argument should either be True or " "False." ) if not isinstance ( num_blocks , int ) : raise ValueError ( 'The `num_blocks` argument should be integer' ) elif num_blocks <= 0 : raise ValueError ( 'The `num_blocks` argument cannot be less than or equal to ' 'zero' ) if not ( isinstance ( encoder_filters , tuple ) or isinstance ( encoder_filters , list ) ) : raise ValueError ( 'The `encoder_filters` argument should be a list of tuple.' ) elif len ( encoder_filters ) <= 0 : raise ValueError ( 'The `encoder_filters` argument cannot be an empty list.' ) elif len ( encoder_filters ) < num_blocks : raise ValueError ( 'The items of the `encoder_filters` argument cannot be less ' 'than the `num_blocks` argument.' ) if encoder_type . lower ( ) == 'default' : x = input_tensor kernel_size = 3 pool_size = 2 skip_connection_layers = [ ] for filter_id in range ( num_blocks ) : num_filters = encoder_filters [ filter_id ] x = convolution_block ( x , num_filters = num_filters , kernel_size = kernel_size , dilation_rate = 1 , padding = "same" , use_bias = False , use_batchnorm = True , activation = 'relu' ) x = convolution_block ( x , num_filters = num_filters , kernel_size = kernel_size , dilation_rate = 1 , padding = "same" , use_bias = False , use_batchnorm = True , activation = 'relu' ) skip_connection_layers . append ( x ) x = MaxPooling2D ( ( pool_size , pool_size ) ) ( x ) encoder_model_output = x encoder_model = Model ( input_tensor , encoder_model_output ) else : encoder_model = get_encoder_model ( encoder_type , input_tensor , encoder_weights ) skip_connection_layers = get_skip_connection_layers ( encoder_type , encoder_model ) encoder_model_output = get_encoder_model_output_layer ( encoder_type , encoder_model , num_blocks ) encoder_model . trainable = not ( encoder_freeze ) return encoder_model , encoder_model_output , skip_connection_layers
short_docstring: Instantiates  encoder architecture for the U-Net segmmantation model.
short_docstring_tokens: Instantiates encoder architecture for the U - Net segmmantation model .
comment: """
      Instantiates  encoder architecture for the U-Net segmmantation model.
  
      Args:
          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 encoder type is  'Default'.
          input_tensor: a tensorflow tensor input of a tuple containg image width,
                        height and channels respectively.
          encoder_weights: One of `None` (random initialization), `imagenet`,
                           or the path to the weights file to be loaded.
                           Default to None.
          encoder_freeze: Boolean Specifying whether to train encoder parameters
                          or not. Default to False.
          num_blocks: number of blocks to use for each encoder. Default to 5.
          encoder_filters: a list or tuple containing the number of filters to 
                           use for each encoder block. Default to 
                           [32, 64, 128, 256, 512].
      Returns:
          encoder_model: keras model
          encoder_model_output: Encoder model output.
          skip_connection_layers: Skip connection layers/encoder block outputs 
                                  before pooling.
      """$SEP$#------------------------------------------------------------------------------#$SEP$# Validate and preprocess arguments$SEP$#------------------------------------------------------------------------------#$SEP$# 1. encoder_type$SEP$# 2. encoder_weights$SEP$# 3. encoder_freeze$SEP$# 4. num_blocks$SEP$# 5. encoder_filters$SEP$#--------------------------------------------------------------------------#$SEP$# Build the encoding blocks from the arguments specified$SEP$#--------------------------------------------------------------------------#$SEP$#--------------------------------------------------------------------------#$SEP$# 1. Default encoding blocks$SEP$#--------------------------------------------------------------------------#$SEP$# Design the model$SEP$# save block output layer before pooling$SEP$# Create model$SEP$#--------------------------------------------------------------------------#$SEP$# 2. Pretrained model encoding blocks$SEP$#--------------------------------------------------------------------------#$SEP$# Make the model parameters trainable or non trainable