docstr: Args:
      feat (Tensor): Feature tensor of shape :math:`(N, D_m, H, W)`.
      img_metas (dict): A dict that contains meta information of input
          images. Preferably with the key ``valid_ratio``.
  
  Returns:
      Tensor: A tensor of shape :math:`(N, T, D_m)`.
docstr_tok: ["Args",":","feat","(","Tensor",")",":","Feature","tensor","of","shape",":","math",":","`","(","N",",","D_m",",","H",",","W",")","`",".","img_metas","(","dict",")",":","A","dict","that","contains","meta","information","of","input","images",".","Preferably","with","the","key","``","valid_ratio","``",".","Returns",":","Tensor",":","A","tensor","of","shape",":","math",":","`","(","N",",","T",",","D_m",")","`","."]
code: def forward(self, feat, valid_ratios=None):
      """
      Args:
          feat (Tensor): Feature tensor of shape :math:`(N, D_m, H, W)`.
          img_metas (dict): A dict that contains meta information of input
              images. Preferably with the key ``valid_ratio``.
  
      Returns:
          Tensor: A tensor of shape :math:`(N, T, D_m)`.
      """
      if valid_ratios is None:
          valid_ratios = [1.0 for _ in range(feat.shape[0])]
      feat = self.position_enc(feat)
      n, c, h, w = feat.shape
  
      mask = paddle.zeros((n, h, w))
      for i, valid_ratio in enumerate(valid_ratios):
          valid_width = min(w, math.ceil(w * valid_ratio))
          mask[i, :, :valid_width] = 1
  
      mask = mask.reshape([n, h * w])
      feat = feat.reshape([n, c, h * w])
  
      output = feat.transpose([0, 2, 1])
      for enc_layer in self.layer_stack:
          output = enc_layer(output, h, w, mask)
      output = self.layer_norm(output)
  
      return output
  
imports: import math
  import numpy
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle import ParamAttr, reshape, transpose
  from paddle.nn import Conv2D, BatchNorm, Linear, Dropout
  from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
  from paddle.nn.initializer import KaimingNormal, Uniform, Constant
label_desc: Use image node_id 2 for calling the SATRNEncoder obj's underlying member method code with example usage: obj.forward(feat, valid_ratios) and returns: output