code: def __init__(
      self,
      output_image_size=None,
      num_control_points=None,
      margins=None,
  ):
      super(TPSSpatialTransformer, self).__init__()
      self.output_image_size = output_image_size
      self.num_control_points = num_control_points
      self.margins = margins
  
      self.target_height, self.target_width = output_image_size
      target_control_points = build_output_control_points(
          num_control_points, margins
      )
      N = num_control_points
  
      # create padded kernel matrix
      forward_kernel = paddle.zeros(shape=[N + 3, N + 3])
      target_control_partial_repr = compute_partial_repr(
          target_control_points, target_control_points
      )
      target_control_partial_repr = paddle.cast(
          target_control_partial_repr, forward_kernel.dtype
      )
      forward_kernel[:N, :N] = target_control_partial_repr
      forward_kernel[:N, -3] = 1
      forward_kernel[-3, :N] = 1
      target_control_points = paddle.cast(
          target_control_points, forward_kernel.dtype
      )
      forward_kernel[:N, -2:] = target_control_points
      forward_kernel[-2:, :N] = paddle.transpose(
          target_control_points, perm=[1, 0]
      )
      # compute inverse matrix
      inverse_kernel = paddle.inverse(forward_kernel)
  
      # create target cordinate matrix
      HW = self.target_height * self.target_width
      target_coordinate = list(
          itertools.product(
              range(self.target_height), range(self.target_width)
          )
      )
      target_coordinate = paddle.to_tensor(target_coordinate)  # HW x 2
      Y, X = paddle.split(
          target_coordinate, target_coordinate.shape[1], axis=1
      )
      Y = Y / (self.target_height - 1)
      X = X / (self.target_width - 1)
      target_coordinate = paddle.concat(
          [X, Y], axis=1
      )  # convert from (y, x) to (x, y)
      target_coordinate_partial_repr = compute_partial_repr(
          target_coordinate, target_control_points
      )
      target_coordinate_repr = paddle.concat(
          [
              target_coordinate_partial_repr,
              paddle.ones(shape=[HW, 1]),
              target_coordinate,
          ],
          axis=1,
      )
  
      # register precomputed matrices
      self.inverse_kernel = inverse_kernel
      self.padding_matrix = paddle.zeros(shape=[3, 2])
      self.target_coordinate_repr = target_coordinate_repr
      self.target_control_points = target_control_points
  
file_path: PaddleOCR/ppocr/modeling/transforms/tps_spatial_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 itertools
label_desc: Use image node_id 1 to create a new TPSSpatialTransformer object from inherited base classes: nn with example: obj = TPSSpatialTransformer(output_image_size, num_control_points, margins)