class_docstr: Sturture-Preserving Transformation (SPT) as Equa. (2) in Ref. [1]
  Ref: [1] SPIN: Structure-Preserving Inner Offset Network for Scene Text Recognition. AAAI-2021.
class_docstr_tok: ["Sturture-Preserving","Transformation","(","SPT",")","as","Equa",".","(","2",")","in","Ref",".","[","1","]","Ref",":","[","1","]","SPIN",":","Structure-Preserving","Inner","Offset","Network","for","Scene","Text","Recognition",".","AAAI-2021","."]
docstr: Args:
      batch_I (Tensor): batch of input images [batch_size x nc x I_height x I_width]
      weights:
      offsets: the predicted offset by AIN, a scalar
      lambda_color: the learnable update gate lpha in Equa. (5) as
                    g(x) = (1 - lpha) \odot x + lpha \odot x_{offsets}
  
  Returns:
      Tensor: transformed images by SPN as Equa. (4) in Ref. [1]
                  [batch_size x I_channel_num x I_r_height x I_r_width]
docstr_tok: ["Args",":","batch_I","(","Tensor",")",":","batch","of","input","images","[","batch_size","x","nc","x","I_height","x","I_width","]","weights",":","offsets",":","the","predicted","offset","by","AIN",",","a","scalar","lambda_color",":","the","learnable","update","gate","\u0007lpha","in","Equa",".","(","5",")","as","g","(","x",")","=","(","1","-","\u0007lpha",")","\\odot","x","+","\u0007lpha","\\odot","x_","{","offsets","}","Returns",":","Tensor",":","transformed","images","by","SPN","as","Equa",".","(","4",")","in","Ref",".","[","1","]","[","batch_size","x","I_channel_num","x","I_r_height","x","I_r_width","]"]
code: def forward(self, batch_I, weights, offsets, lambda_color=None):
      """
  
      Args:
          batch_I (Tensor): batch of input images [batch_size x nc x I_height x I_width]
          weights:
          offsets: the predicted offset by AIN, a scalar
          lambda_color: the learnable update gate \alpha in Equa. (5) as
                        g(x) = (1 - \alpha) \odot x + \alpha \odot x_{offsets}
  
      Returns:
          Tensor: transformed images by SPN as Equa. (4) in Ref. [1]
                      [batch_size x I_channel_num x I_r_height x I_r_width]
  
      """
      batch_I = (batch_I + 1) * 0.5
      if offsets is not None:
          batch_I = (
              batch_I * (1 - lambda_color) + offsets * lambda_color
          )
      batch_weight_params = paddle.unsqueeze(
          paddle.unsqueeze(weights, -1), -1
      )
      batch_I_power = paddle.stack(
          [batch_I.pow(p) for p in self.power_list], axis=1
      )
  
      batch_weight_sum = paddle.sum(
          batch_I_power * batch_weight_params, axis=1
      )
      batch_weight_sum = self.bn(batch_weight_sum)
      batch_weight_sum = self.sigmoid(batch_weight_sum)
      batch_weight_sum = batch_weight_sum * 2 - 1
      return batch_weight_sum
  
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 3 for calling the SP_TransformerNetwork obj's underlying member method code with example usage: obj.forward(batch_I, weights, offsets, lambda_color) and returns: batch_weight_sum