class_docstr: Pack the inputs data for text recognition.
  
  The type of outputs is `dict`:
  
  - inputs: Image as a tensor, whose shape is (C, H, W).
  - data_samples: Two components of ``TextRecogDataSample`` will be updated:
  
    - gt_text (LabelData):
  
      - item(str): The groundtruth of text. Rename from 'gt_texts'.
  
    - metainfo (dict): 'metainfo' is always populated. The contents of the
      'metainfo' depends on ``meta_keys``. By default it includes:
  
      - "img_path": Path to the image file.
      - "ori_shape":  Shape of the preprocessed image as a tuple
        (h, w).
      - "img_shape": Shape of the image input to the network as a tuple
        (h, w). Note that the image may be zero-padded afterward on the
        bottom/right if the batch tensor is larger than this shape.
      - "valid_ratio": The proportion of valid (unpadded) content of image
        on the x-axis. It defaults to 1 if not set in pipeline.
  
  Args:
      meta_keys (Sequence[str], optional): Meta keys to be converted to
          the metainfo of ``TextRecogDataSampel``. Defaults to
          ``('img_path', 'ori_shape', 'img_shape', 'pad_shape',
          'valid_ratio')``.
docstr: Method to pack the input data.
  
  Args:
      results (dict): Result dict from the data pipeline.
  
  Returns:
      dict:
  
      - 'inputs' (obj:`torch.Tensor`): Data for model forwarding.
      - 'data_samples' (obj:`TextRecogDataSample`): The annotation info
          of the sample.
docstr_tok: ["Method","to","pack","the","input","data",".","Args",":","results","(","dict",")",":","Result","dict","from","the","data","pipeline",".","Returns",":","dict",":","-","'inputs","'","(","obj",":","`","torch.Tensor","`",")",":","Data","for","model","forwarding",".","-","'data_samples","'","(","obj",":","`","TextRecogDataSample","`",")",":","The","annotation","info","of","the","sample","."]
code: def transform(self, results: dict) -> dict:
      """Method to pack the input data.
  
      Args:
          results (dict): Result dict from the data pipeline.
  
      Returns:
          dict:
  
          - 'inputs' (obj:`torch.Tensor`): Data for model forwarding.
          - 'data_samples' (obj:`TextRecogDataSample`): The annotation info
              of the sample.
      """
      packed_results = dict()
      if "img" in results:
          img = results["img"]
          if len(img.shape) < 3:
              img = np.expand_dims(img, -1)
          # A simple trick to speedup formatting by 3-5 times when
          # OMP_NUM_THREADS != 1
          # Refer to https://github.com/open-mmlab/mmdetection/pull/9533
          # for more details
          if img.flags.c_contiguous:
              img = to_tensor(img)
              img = img.permute(2, 0, 1).contiguous()
          else:
              img = np.ascontiguousarray(img.transpose(2, 0, 1))
              img = to_tensor(img)
          packed_results["inputs"] = img
  
      data_sample = TextRecogDataSample()
      gt_text = LabelData()
  
      if results.get("gt_texts", None):
          assert (
              len(results["gt_texts"]) == 1
          ), "Each image sample should have one text annotation only"
          gt_text.item = results["gt_texts"][0]
      data_sample.gt_text = gt_text
  
      img_meta = {}
      for key in self.meta_keys:
          if key == "valid_ratio":
              img_meta[key] = results.get("valid_ratio", 1)
          else:
              img_meta[key] = results[key]
      data_sample.set_metainfo(img_meta)
  
      packed_results["data_samples"] = data_sample
  
      return packed_results
  
imports: import numpy
  import torch
  from mmcv.transforms import to_tensor
  from mmcv.transforms.base import BaseTransform
  from mmengine.structures import InstanceData, LabelData
  from mmocr.registry import TRANSFORMS
  from mmocr.structures import KIEDataSample, TextDetDataSample, TextRecogDataSample
label_desc: Use image node_id 2 for calling the PackTextRecogInputs obj's underlying member method code with example usage: obj.transform(results) and returns: packed_results