class_docstr: Geometric-Absorbed SPIN Transformation (GA-SPIN) proposed in Ref. [1]
  
  
  Ref: [1] SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition. AAAI-2021.
class_docstr_tok: ["Geometric-Absorbed","SPIN","Transformation","(","GA-SPIN",")","proposed","in","Ref",".","[","1","]","Ref",":","[","1","]","SPIN",":","Structure-Preserving","Inner","Offset","Network","for","Scene","Text","Recognition",".","AAAI-2021","."]
docstr: Args:
      in_channels (int): channel of input features,
                          set it to 1 if the grayscale images and 3 if RGB input
      I_r_size (tuple): size of rectified images (used in STN transformations)
      offsets (bool): set it to False if use SPN w.o. AIN,
                      and set it to True if use SPIN (both with SPN and AIN)
      norm_type (str): the normalization type of the module,
                      set it to 'BN' by default, 'IN' optionally
      default_type (int): the K chromatic space,
                          set it to 3/5/6 depend on the complexity of transformation intensities
      loc_lr (float): learning rate of location network
      stn (bool): whther to use stn.
docstr_tok: ["Args",":","in_channels","(","int",")",":","channel","of","input","features",",","set","it","to","1","if","the","grayscale","images","and","3","if","RGB","input","I_r_size","(","tuple",")",":","size","of","rectified","images","(","used","in","STN","transformations",")","offsets","(","bool",")",":","set","it","to","False","if","use","SPN","w.o",".","AIN",",","and","set","it","to","True","if","use","SPIN","(","both","with","SPN","and","AIN",")","norm_type","(","str",")",":","the","normalization","type","of","the","module",",","set","it","to","'BN","'","by","default",",","'IN","'","optionally","default_type","(","int",")",":","the","K","chromatic","space",",","set","it","to","3\/5\/6","depend","on","the","complexity","of","transformation","intensities","loc_lr","(","float",")",":","learning","rate","of","location","network","stn","(","bool",")",":","whther","to","use","stn","."]
code: def __init__(
      self,
      in_channels=1,
      I_r_size=(32, 100),
      offsets=False,
      norm_type="BN",
      default_type=6,
      loc_lr=1,
      stn=True,
  ):
      """
      Args:
          in_channels (int): channel of input features,
                              set it to 1 if the grayscale images and 3 if RGB input
          I_r_size (tuple): size of rectified images (used in STN transformations)
          offsets (bool): set it to False if use SPN w.o. AIN,
                          and set it to True if use SPIN (both with SPN and AIN)
          norm_type (str): the normalization type of the module,
                          set it to 'BN' by default, 'IN' optionally
          default_type (int): the K chromatic space,
                              set it to 3/5/6 depend on the complexity of transformation intensities
          loc_lr (float): learning rate of location network
          stn (bool): whther to use stn.
  
      """
      super(GA_SPIN_Transformer, self).__init__()
      self.nc = in_channels
      self.spt = True
      self.offsets = offsets
      self.stn = (
          stn  # set to True in GA-SPIN, while set it to False in SPIN
      )
      self.I_r_size = I_r_size
      self.out_channels = in_channels
      if norm_type == "BN":
          norm_layer = functools.partial(
              nn.BatchNorm2D, use_global_stats=True
          )
      elif norm_type == "IN":
          norm_layer = functools.partial(
              nn.InstanceNorm2D,
              weight_attr=False,
              use_global_stats=False,
          )
      else:
          raise NotImplementedError(
              "normalization layer [%s] is not found" % norm_type
          )
  
      if self.spt:
          self.sp_net = SP_TransformerNetwork(in_channels, default_type)
          self.spt_convnet = nn.Sequential(
              # 32*100
              nn.Conv2D(in_channels, 32, 3, 1, 1, bias_attr=False),
              norm_layer(32),
              nn.ReLU(),
              nn.MaxPool2D(kernel_size=2, stride=2),
              # 16*50
              nn.Conv2D(32, 64, 3, 1, 1, bias_attr=False),
              norm_layer(64),
              nn.ReLU(),
              nn.MaxPool2D(kernel_size=2, stride=2),
              # 8*25
              nn.Conv2D(64, 128, 3, 1, 1, bias_attr=False),
              norm_layer(128),
              nn.ReLU(),
              nn.MaxPool2D(kernel_size=2, stride=2),
              # 4*12
          )
          self.stucture_fc1 = nn.Sequential(
              nn.Conv2D(128, 256, 3, 1, 1, bias_attr=False),
              norm_layer(256),
              nn.ReLU(),
              nn.MaxPool2D(kernel_size=2, stride=2),
              nn.Conv2D(256, 256, 3, 1, 1, bias_attr=False),
              norm_layer(256),
              nn.ReLU(),  # 2*6
              nn.MaxPool2D(kernel_size=2, stride=2),
              nn.Conv2D(256, 512, 3, 1, 1, bias_attr=False),
              norm_layer(512),
              nn.ReLU(),  # 1*3
              nn.AdaptiveAvgPool2D(1),
              nn.Flatten(1, -1),  # batch_size x 512
              nn.Linear(
                  512, 256, weight_attr=nn.initializer.Normal(0.001)
              ),
              nn.BatchNorm1D(256),
              nn.ReLU(),
          )
          self.out_weight = 2 * default_type + 1
          self.spt_length = 2 * default_type + 1
          if offsets:
              self.out_weight += 1
          if self.stn:
              self.F = 20
              self.out_weight += self.F * 2
              self.GridGenerator = GridGenerator(self.F * 2, self.F)
  
          # self.out_weight*=nc
          # Init structure_fc2 in LocalizationNetwork
          initial_bias = self.init_spin(default_type * 2)
          initial_bias = initial_bias.reshape(-1)
          param_attr = ParamAttr(
              learning_rate=loc_lr,
              initializer=nn.initializer.Assign(
                  np.zeros([256, self.out_weight])
              ),
          )
          bias_attr = ParamAttr(
              learning_rate=loc_lr,
              initializer=nn.initializer.Assign(initial_bias),
          )
          self.stucture_fc2 = nn.Linear(
              256,
              self.out_weight,
              weight_attr=param_attr,
              bias_attr=bias_attr,
          )
          self.sigmoid = nn.Sigmoid()
  
          if offsets:
              self.offset_fc1 = nn.Sequential(
                  nn.Conv2D(128, 16, 3, 1, 1, bias_attr=False),
                  norm_layer(16),
                  nn.ReLU(),
              )
              self.offset_fc2 = nn.Conv2D(16, in_channels, 3, 1, 1)
              self.pool = nn.MaxPool2D(2, 2)
  
file_path: PaddleOCR/ppocr/modeling/transforms/gaspin_transformer.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import paddle
  from paddle import nn, ParamAttr
  from paddle.nn import functional
  import numpy
  import functools
  from .tps import GridGenerator
label_desc: Use image node_id 1 to create a new GA_SPIN_Transformer object from inherited base classes: nn with example: obj = GA_SPIN_Transformer(in_channels, I_r_size, offsets, norm_type, default_type, loc_lr, stn)