class_docstr: MLM+VRM, MLM is only used in training.
  ratio controls the occluded number in a batch.
  The pipeline of VisionLAN in testing is very concise with only a backbone + sequence modeling(transformer unit) + prediction layer(pp layer).
  x: input image
  label_pos: character index
  training_step: LF or LA process
  output
  text_pre: prediction of VRM
  test_rem: prediction of remaining string in MLM
  text_mas: prediction of occluded character in MLM
  mask_c_show: visualization of Mask_c
class_docstr_tok: ["MLM+VRM",",","MLM","is","only","used","in","training",".","ratio","controls","the","occluded","number","in","a","batch",".","The","pipeline","of","VisionLAN","in","testing","is","very","concise","with","only","a","backbone","+","sequence","modeling","(","transformer","unit",")","+","prediction","layer","(","pp","layer",")",".","x",":","input","image","label_pos",":","character","index","training_step",":","LF","or","LA","process","output","text_pre",":","prediction","of","VRM","test_rem",":","prediction","of","remaining","string","in","MLM","text_mas",":","prediction","of","occluded","character","in","MLM","mask_c_show",":","visualization","of","Mask_c"]
code: def forward(self, x, label_pos, training_step, train_mode=False):
      b, c, h, w = x.shape
      nT = self.max_text_length
      x = paddle.transpose(x, perm=[0, 1, 3, 2])
      x = paddle.reshape(x, [-1, c, h * w])
      x = paddle.transpose(x, perm=[0, 2, 1])
      if train_mode:
          if training_step == "LF_1":
              f_res = 0
              f_sub = 0
              x = self.SequenceModeling(x, src_mask=None)
              text_pre, test_rem, text_mas = self.Prediction(
                  x, f_res, f_sub, train_mode=True, use_mlm=False
              )
              return text_pre, text_pre, text_pre, text_pre
          elif training_step == "LF_2":
              # MLM
              f_res, f_sub, mask_c = self.MLM(x, label_pos)
              x = self.SequenceModeling(x, src_mask=None)
              text_pre, test_rem, text_mas = self.Prediction(
                  x, f_res, f_sub, train_mode=True
              )
              mask_c_show = trans_1d_2d(mask_c)
              return text_pre, test_rem, text_mas, mask_c_show
          elif training_step == "LA":
              # MLM
              f_res, f_sub, mask_c = self.MLM(x, label_pos)
              ## use the mask_c (1 for occluded character and 0 for remaining characters) to occlude input
              ## ratio controls the occluded number in a batch
              character_mask = paddle.zeros_like(mask_c)
  
              ratio = b // 2
              if ratio >= 1:
                  with paddle.no_grad():
                      character_mask[0:ratio, :, :] = mask_c[
                          0:ratio, :, :
                      ]
              else:
                  character_mask = mask_c
              x = x * (1 - character_mask)
              # VRM
              ## transformer unit for VRM
              x = self.SequenceModeling(x, src_mask=None)
              ## prediction layer for MLM and VSR
              text_pre, test_rem, text_mas = self.Prediction(
                  x, f_res, f_sub, train_mode=True
              )
              mask_c_show = trans_1d_2d(mask_c)
              return text_pre, test_rem, text_mas, mask_c_show
          else:
              raise NotImplementedError
      else:  # VRM is only used in the testing stage
          f_res = 0
          f_sub = 0
          contextual_feature = self.SequenceModeling(x, src_mask=None)
          text_pre = self.Prediction(
              contextual_feature,
              f_res,
              f_sub,
              train_mode=False,
              use_mlm=False,
          )
          text_pre = paddle.transpose(
              text_pre, perm=[1, 0, 2]
          )  # (26, b, 37))
          return text_pre, x
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  from paddle import ParamAttr
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.initializer import Normal, XavierNormal
  import numpy
label_desc: Use image node_id 2 for calling the MLM_VRM obj's underlying member method code with example usage: obj.forward(x, label_pos, training_step, train_mode) and returns: text_pre,  x, text_pre,  text_pre,  text_pre,  text_pre, text_pre,  test_rem,  text_mas,  mask_c_show, text_pre,  test_rem,  text_mas,  mask_c_show