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","]","."]
docstr: Forward function of STN.
  
  Args:
      img (Tensor): The input image tensor.
  
  Returns:
      Tensor: The rectified image tensor.
docstr_tok: ["Forward","function","of","STN",".","Args",":","img","(","Tensor",")",":","The","input","image","tensor",".","Returns",":","Tensor",":","The","rectified","image","tensor","."]
code: def forward(self, img: torch.Tensor) -> torch.Tensor:
      """Forward function of STN.
  
      Args:
          img (Tensor): The input image tensor.
  
      Returns:
          Tensor: The rectified image tensor.
      """
      resize_img = F.interpolate(
          img,
          self.resized_image_size,
          mode="bilinear",
          align_corners=True,
      )
      points = self.stn_convnet(resize_img)
      batch_size, _, _, _ = points.size()
      points = points.view(batch_size, -1)
      img_feat = self.stn_fc1(points)
      points = self.stn_fc2(0.1 * img_feat)
      points = points.view(-1, self.num_control_points, 2)
  
      transformd_image = self.tps(img, points)
      return transformd_image
  
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 3 for calling the STN obj's underlying member method code with example usage: obj.forward(img) and returns: transformd_image