class_docstr: Postprocessor for SDMGR. It converts the node and edge scores into
  labels and edge labels. If the link_type is not "none", it reconstructs the
  edge labels with different strategies specified by ``link_type``, which is
  generally known as the "openset" mode. In "openset" mode, only the edges
  connecting from "key" to "value" nodes will be constructed.
  
  Args:
      link_type (str): The type of link to be constructed.
          Defaults to 'none'. Options are:
  
          - 'none': The simplest link type involving no edge
            postprocessing. The edge prediction will be returned as-is.
          - 'one-to-one': One key node can be connected to one value node.
          - 'one-to-many': One key node can be connected to multiple value
            nodes.
          - 'many-to-one': Multiple key nodes can be connected to one value
            node.
          - 'many-to-many': No restrictions on the number of edges that a
            key/value node can have.
      key_node_idx (int, optional): The label index of the key node. It must
          be specified if ``link_type`` is not "none". Defaults to None.
      value_node_idx (int, optional): The index of the value node. It must be
          specified if ``link_type`` is not "none". Defaults to None.
docstr: Postprocess raw outputs from SDMGR heads and pack the results into a
  list of KIEDataSample.
  
  Args:
      preds (tuple[Tensor]): A tuple of raw outputs from SDMGR heads.
      data_samples (list[KIEDataSample]): A list of N datasamples,
          containing meta information and gold annotations for each of
          the images.
  
  Returns:
      List[KIEDataSample]: A list of datasamples of prediction results.
      Results are stored in ``pred_instances.labels``,
      ``pred_instances.scores``, ``pred_instances.edge_labels`` and
      ``pred_instances.edge_scores``.
  
      - labels (Tensor): An integer tensor of shape (N, ) indicating bbox
        labels for each image.
      - scores (Tensor): A float tensor of shape (N, ), indicating the
        confidence scores for node label predictions.
      - edge_labels (Tensor): An integer tensor of shape (N, N)
        indicating the connection between nodes. Options are 0, 1.
      - edge_scores (Tensor): A float tensor of shape (N, ), indicating
        the confidence scores for edge predictions.
docstr_tok: ["Postprocess","raw","outputs","from","SDMGR","heads","and","pack","the","results","into","a","list","of","KIEDataSample",".","Args",":","preds","(","tuple","[","Tensor","]",")",":","A","tuple","of","raw","outputs","from","SDMGR","heads",".","data_samples","(","list","[","KIEDataSample","]",")",":","A","list","of","N","datasamples",",","containing","meta","information","and","gold","annotations","for","each","of","the","images",".","Returns",":","List","[","KIEDataSample","]",":","A","list","of","datasamples","of","prediction","results",".","Results","are","stored","in","``","pred_instances.labels","``",",","``","pred_instances.scores","``",",","``","pred_instances.edge_labels","``","and","``","pred_instances.edge_scores","``",".","-","labels","(","Tensor",")",":","An","integer","tensor","of","shape","(","N",",",")","indicating","bbox","labels","for","each","image",".","-","scores","(","Tensor",")",":","A","float","tensor","of","shape","(","N",",",")",",","indicating","the","confidence","scores","for","node","label","predictions",".","-","edge_labels","(","Tensor",")",":","An","integer","tensor","of","shape","(","N",",","N",")","indicating","the","connection","between","nodes",".","Options","are","0",",","1",".","-","edge_scores","(","Tensor",")",":","A","float","tensor","of","shape","(","N",",",")",",","indicating","the","confidence","scores","for","edge","predictions","."]
code: def __call__(
      self,
      preds: Tuple[Tensor, Tensor],
      data_samples: List[KIEDataSample],
  ) -> List[KIEDataSample]:
      """Postprocess raw outputs from SDMGR heads and pack the results into a
      list of KIEDataSample.
  
      Args:
          preds (tuple[Tensor]): A tuple of raw outputs from SDMGR heads.
          data_samples (list[KIEDataSample]): A list of N datasamples,
              containing meta information and gold annotations for each of
              the images.
  
      Returns:
          List[KIEDataSample]: A list of datasamples of prediction results.
          Results are stored in ``pred_instances.labels``,
          ``pred_instances.scores``, ``pred_instances.edge_labels`` and
          ``pred_instances.edge_scores``.
  
          - labels (Tensor): An integer tensor of shape (N, ) indicating bbox
            labels for each image.
          - scores (Tensor): A float tensor of shape (N, ), indicating the
            confidence scores for node label predictions.
          - edge_labels (Tensor): An integer tensor of shape (N, N)
            indicating the connection between nodes. Options are 0, 1.
          - edge_scores (Tensor): A float tensor of shape (N, ), indicating
            the confidence scores for edge predictions.
      """
      node_preds, edge_preds = preds
      all_node_scores = self.softmax(node_preds)
      all_edge_scores = self.softmax(edge_preds)
      chunk_size = [
          data_sample.gt_instances.bboxes.shape[0]
          for data_sample in data_samples
      ]
      node_scores, node_preds = torch.max(all_node_scores, dim=-1)
      edge_scores, edge_preds = torch.max(all_edge_scores, dim=-1)
      node_preds = node_preds.split(chunk_size, dim=0)
      node_scores = node_scores.split(chunk_size, dim=0)
  
      sq_chunks = [chunk**2 for chunk in chunk_size]
      edge_preds = list(edge_preds.split(sq_chunks, dim=0))
      edge_scores = list(edge_scores.split(sq_chunks, dim=0))
      for i, chunk in enumerate(chunk_size):
          edge_preds[i] = edge_preds[i].reshape((chunk, chunk))
          edge_scores[i] = edge_scores[i].reshape((chunk, chunk))
  
      for i in range(len(data_samples)):
          data_samples[i].pred_instances = InstanceData()
          data_samples[i].pred_instances.labels = node_preds[i].cpu()
          data_samples[i].pred_instances.scores = node_scores[i].cpu()
          if self.link_type != "none":
              edge_scores[i], edge_preds[i] = self.decode_edges(
                  node_preds[i], edge_scores[i], edge_preds[i]
              )
          data_samples[i].pred_instances.edge_labels = edge_preds[
              i
          ].cpu()
          data_samples[i].pred_instances.edge_scores = edge_scores[
              i
          ].cpu()
  
      return data_samples
  
file_path: mmocr/mmocr/models/kie/postprocessors/sdmgr_postprocessor.py
imports: from typing import List, Optional, Tuple
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor, nn
  from mmocr.registry import MODELS
  from mmocr.structures import KIEDataSample
label_desc: Use image node_id 2 for calling the SDMGRPostProcessor obj's underlying member method code with example usage: obj.__call__(preds, data_samples) and returns: data_samples