class_docstr: Args:
      enc_bi_rnn (bool): If True, use bidirectional RNN in encoder.
      enc_drop_rnn (float): Dropout probability of RNN layer in encoder.
      enc_gru (bool): If True, use GRU, else LSTM in encoder.
      d_model (int): Dim of channels from backbone.
      d_enc (int): Dim of encoder RNN layer.
      mask (bool): If True, mask padding in RNN sequence.
class_docstr_tok: ["Args",":","enc_bi_rnn","(","bool",")",":","If","True",",","use","bidirectional","RNN","in","encoder",".","enc_drop_rnn","(","float",")",":","Dropout","probability","of","RNN","layer","in","encoder",".","enc_gru","(","bool",")",":","If","True",",","use","GRU",",","else","LSTM","in","encoder",".","d_model","(","int",")",":","Dim","of","channels","from","backbone",".","d_enc","(","int",")",":","Dim","of","encoder","RNN","layer",".","mask","(","bool",")",":","If","True",",","mask","padding","in","RNN","sequence","."]
code: def forward(self, feat, img_metas=None):
      if img_metas is not None:
          assert len(img_metas[0]) == paddle.shape(feat)[0]
  
      valid_ratios = None
      if img_metas is not None and self.mask:
          valid_ratios = img_metas[-1]
  
      h_feat = feat.shape[2]  # bsz c h w
      feat_v = F.max_pool2d(
          feat, kernel_size=(h_feat, 1), stride=1, padding=0
      )
      feat_v = feat_v.squeeze(2)  # bsz * C * W
      feat_v = paddle.transpose(feat_v, perm=[0, 2, 1])  # bsz * W * C
      holistic_feat = self.rnn_encoder(feat_v)[0]  # bsz * T * C
  
      if valid_ratios is not None:
          valid_hf = []
          T = paddle.shape(holistic_feat)[1]
          for i in range(paddle.shape(valid_ratios)[0]):
              valid_step = (
                  paddle.minimum(
                      T,
                      paddle.ceil(valid_ratios[i] * T).astype("int32"),
                  )
                  - 1
              )
              valid_hf.append(holistic_feat[i, valid_step, :])
          valid_hf = paddle.stack(valid_hf, axis=0)
      else:
          valid_hf = holistic_feat[:, -1, :]  # bsz * C
      holistic_feat = self.linear(valid_hf)  # bsz * C
  
      return holistic_feat
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import paddle
  from paddle import ParamAttr
  import paddle.nn
  import paddle.nn.functional
label_desc: Use image node_id 2 for calling the SAREncoder obj's underlying member method code with example usage: obj.forward(feat, img_metas) and returns: holistic_feat