parameters: (input_tensor, filter_num_begin, depth,
                        stack_num_down, stack_num_up, 
                        patch_size, num_heads, window_size,
                        num_mlp, shift_window=True,
                        name='swin_unet')
return_statement: return X
docstring: The base of SwinUNET.
docstring_summary: The base of SwinUNET.
docstring_tokens: The base of SwinUNET .
function: def swin_unet_2d_base(input_tensor, filter_num_begin, depth,
                        stack_num_down, stack_num_up, 
                        patch_size, num_heads, window_size,
                        num_mlp, shift_window=True,
                        name='swin_unet'):
      '''
      The base of SwinUNET.
      '''
      # Compute number be patches to be embeded
      input_size = input_tensor.shape.as_list()[1:]
      num_patch_x = input_size[0]//patch_size[0]
      num_patch_y = input_size[1]//patch_size[1]
      
      # Number of Embedded dimensions
      embed_dim = filter_num_begin
      
      depth_ = depth
      
      X_skip = []
  
      X = input_tensor
      
      # Patch extraction
      X = transformer_layers.patch_extract(patch_size)(X)
  
      # Embed patches to tokens
      X = transformer_layers.patch_embedding(num_patch_x*num_patch_y, embed_dim)(X)
      
      # The first Swin Transformer stack
      X = swin_transformer_stack(X, stack_num=stack_num_down, 
                                 embed_dim=embed_dim, num_patch=(num_patch_x, num_patch_y), 
                                 num_heads=num_heads[0], window_size=window_size[0], num_mlp=num_mlp, 
                                 shift_window=shift_window, name='{}_swin_down0'.format(name))
      X_skip.append(X)
      
      # Downsampling blocks
      for i in range(depth_-1):
          
          # Patch merging
          X = transformer_layers.patch_merging((num_patch_x, num_patch_y),
                                               embed_dim=embed_dim, name='down{}'.format(i))(X)
          print(X)
          
          # update token shape info
          embed_dim = embed_dim*2
          num_patch_x = num_patch_x//2
          num_patch_y = num_patch_y//2
          
          # Swin Transformer stacks
          X = swin_transformer_stack(X, stack_num=stack_num_down, 
                                     embed_dim=embed_dim, num_patch=(num_patch_x, num_patch_y), 
                                     num_heads=num_heads[i+1], window_size=window_size[i+1], num_mlp=num_mlp, 
                                     shift_window=shift_window, name='{}_swin_down{}'.format(name, i+1))
          
          # Store tensors for concat
          X_skip.append(X)
          
      # reverse indexing encoded tensors and hyperparams
      X_skip = X_skip[::-1]
      num_heads = num_heads[::-1]
      window_size = window_size[::-1]
      
      # upsampling begins at the deepest available tensor
      X = X_skip[0]
      
      # other tensors are preserved for concatenation
      X_decode = X_skip[1:]
      
      depth_decode = len(X_decode)
      
      for i in range(depth_decode):
          
          # Patch expanding
          X = transformer_layers.patch_expanding(num_patch=(num_patch_x, num_patch_y), 
                                                 embed_dim=embed_dim, upsample_rate=2,
                                                 return_vector=True)(X)
          
  
          # update token shape info
          embed_dim = embed_dim//2
          num_patch_x = num_patch_x*2
          num_patch_y = num_patch_y*2
          
          # Concatenation and linear projection
          X = concatenate([X, X_decode[i]], axis=-1, name='{}_concat_{}'.format(name, i))
          X = Dense(embed_dim, use_bias=False, name='{}_concat_linear_proj_{}'.format(name, i))(X)
          
          # Swin Transformer stacks
          X = swin_transformer_stack(X, stack_num=stack_num_up, 
                             embed_dim=embed_dim, num_patch=(num_patch_x, num_patch_y), 
                             num_heads=num_heads[i], window_size=window_size[i], num_mlp=num_mlp, 
                             shift_window=shift_window, name='{}_swin_up{}'.format(name, i))
          
      # The last expanding layer; it produces full-size feature maps based on the patch size
      # !!! <--- "patch_size[0]" is used; it assumes patch_size = (size, size)
      X = transformer_layers.patch_expanding(num_patch=(num_patch_x, num_patch_y), 
                                             embed_dim=embed_dim, upsample_rate=patch_size[0],
                                             return_vector=False)(X)
      
      return X
function_tokens: def swin_unet_2d_base ( input_tensor , filter_num_begin , depth , stack_num_down , stack_num_up , patch_size , num_heads , window_size , num_mlp , shift_window = True , name = 'swin_unet' ) : # Compute number be patches to be embeded input_size = input_tensor . shape . as_list ( ) [ 1 : ] num_patch_x = input_size [ 0 ] // patch_size [ 0 ] num_patch_y = input_size [ 1 ] // patch_size [ 1 ] # Number of Embedded dimensions embed_dim = filter_num_begin depth_ = depth X_skip = [ ] X = input_tensor # Patch extraction X = transformer_layers . patch_extract ( patch_size ) ( X ) # Embed patches to tokens X = transformer_layers . patch_embedding ( num_patch_x * num_patch_y , embed_dim ) ( X ) # The first Swin Transformer stack X = swin_transformer_stack ( X , stack_num = stack_num_down , embed_dim = embed_dim , num_patch = ( num_patch_x , num_patch_y ) , num_heads = num_heads [ 0 ] , window_size = window_size [ 0 ] , num_mlp = num_mlp , shift_window = shift_window , name = '{}_swin_down0' . format ( name ) ) X_skip . append ( X ) # Downsampling blocks for i in range ( depth_ - 1 ) : # Patch merging X = transformer_layers . patch_merging ( ( num_patch_x , num_patch_y ) , embed_dim = embed_dim , name = 'down{}' . format ( i ) ) ( X ) print ( X ) # update token shape info embed_dim = embed_dim * 2 num_patch_x = num_patch_x // 2 num_patch_y = num_patch_y // 2 # Swin Transformer stacks X = swin_transformer_stack ( X , stack_num = stack_num_down , embed_dim = embed_dim , num_patch = ( num_patch_x , num_patch_y ) , num_heads = num_heads [ i + 1 ] , window_size = window_size [ i + 1 ] , num_mlp = num_mlp , shift_window = shift_window , name = '{}_swin_down{}' . format ( name , i + 1 ) ) # Store tensors for concat X_skip . append ( X ) # reverse indexing encoded tensors and hyperparams X_skip = X_skip [ : : - 1 ] num_heads = num_heads [ : : - 1 ] window_size = window_size [ : : - 1 ] # upsampling begins at the deepest available tensor X = X_skip [ 0 ] # other tensors are preserved for concatenation X_decode = X_skip [ 1 : ] depth_decode = len ( X_decode ) for i in range ( depth_decode ) : # Patch expanding X = transformer_layers . patch_expanding ( num_patch = ( num_patch_x , num_patch_y ) , embed_dim = embed_dim , upsample_rate = 2 , return_vector = True ) ( X ) # update token shape info embed_dim = embed_dim // 2 num_patch_x = num_patch_x * 2 num_patch_y = num_patch_y * 2 # Concatenation and linear projection X = concatenate ( [ X , X_decode [ i ] ] , axis = - 1 , name = '{}_concat_{}' . format ( name , i ) ) X = Dense ( embed_dim , use_bias = False , name = '{}_concat_linear_proj_{}' . format ( name , i ) ) ( X ) # Swin Transformer stacks X = swin_transformer_stack ( X , stack_num = stack_num_up , embed_dim = embed_dim , num_patch = ( num_patch_x , num_patch_y ) , num_heads = num_heads [ i ] , window_size = window_size [ i ] , num_mlp = num_mlp , shift_window = shift_window , name = '{}_swin_up{}' . format ( name , i ) ) # The last expanding layer; it produces full-size feature maps based on the patch size # !!! <--- "patch_size[0]" is used; it assumes patch_size = (size, size) X = transformer_layers . patch_expanding ( num_patch = ( num_patch_x , num_patch_y ) , embed_dim = embed_dim , upsample_rate = patch_size [ 0 ] , return_vector = False ) ( X ) return X