class_docstr: Implement STN module in ASTER: An Attentional Scene Text Recognizer with
  Flexible Rectification
  (https://ieeexplore.ieee.org/abstract/document/8395027/)
  
  Args:
      in_channels (int): The number of input channels.
      resized_image_size (Tuple[int, int]): The resized image size. The input
          image will be downsampled to have a better recitified result.
      output_image_size: The size of the output image for TPS. Defaults to
          (32, 100).
      num_control_points: The number of control points. Defaults to 20.
      margins: The margins for control points to the top and down side of the
          image for TPS. Defaults to [0.05, 0.05].
class_docstr_tok: ["Implement","STN","module","in","ASTER",":","An","Attentional","Scene","Text","Recognizer","with","Flexible","Rectification","(","https",":","\/\/ieeexplore.ieee.org\/abstract\/document\/8395027\/",")","Args",":","in_channels","(","int",")",":","The","number","of","input","channels",".","resized_image_size","(","Tuple","[","int",",","int","]",")",":","The","resized","image","size",".","The","input","image","will","be","downsampled","to","have","a","better","recitified","result",".","output_image_size",":","The","size","of","the","output","image","for","TPS",".","Defaults","to","(","32",",","100",")",".","num_control_points",":","The","number","of","control","points",".","Defaults","to","20.","margins",":","The","margins","for","control","points","to","the","top","and","down","side","of","the","image","for","TPS",".","Defaults","to","[","0.05",",","0.05","]","."]
code: def __init__(
      self,
      in_channels: int,
      resized_image_size: Tuple[int, int] = (32, 64),
      output_image_size: Tuple[int, int] = (32, 100),
      num_control_points: int = 20,
      margins: Tuple[float, float] = [0.05, 0.05],
      init_cfg: Optional[Union[Dict, List[Dict]]] = [
          dict(type="Xavier", layer="Conv2d"),
          dict(type="Constant", val=1, layer="BatchNorm2d"),
      ],
  ):
      super().__init__(init_cfg=init_cfg)
      self.resized_image_size = resized_image_size
      self.num_control_points = num_control_points
      self.tps = TPStransform(
          output_image_size, num_control_points, margins
      )
      self.stn_convnet = nn.Sequential(
          ConvModule(
              in_channels, 32, 3, 1, 1, norm_cfg=dict(type="BN")
          ),
          nn.MaxPool2d(kernel_size=2, stride=2),
          ConvModule(32, 64, 3, 1, 1, norm_cfg=dict(type="BN")),
          nn.MaxPool2d(kernel_size=2, stride=2),
          ConvModule(64, 128, 3, 1, 1, norm_cfg=dict(type="BN")),
          nn.MaxPool2d(kernel_size=2, stride=2),
          ConvModule(128, 256, 3, 1, 1, norm_cfg=dict(type="BN")),
          nn.MaxPool2d(kernel_size=2, stride=2),
          ConvModule(256, 256, 3, 1, 1, norm_cfg=dict(type="BN")),
          nn.MaxPool2d(kernel_size=2, stride=2),
          ConvModule(256, 256, 3, 1, 1, norm_cfg=dict(type="BN")),
      )
  
      self.stn_fc1 = nn.Sequential(
          nn.Linear(2 * 256, 512),
          nn.BatchNorm1d(512),
          nn.ReLU(inplace=True),
      )
      self.stn_fc2 = nn.Linear(512, num_control_points * 2)
      self.init_stn(self.stn_fc2)
  
imports: import itertools
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import ConvModule
  from mmocr.registry import MODELS
  from .base import BasePreprocessor
label_desc: Use image node_id 1 to create a new STN object from inherited base classes: BasePreprocessor with example: obj = STN(in_channels, resized_image_size, output_image_size, num_control_points, margins, init_cfg)