class_docstr: Generate local graphs for GCN to classify the neighbors of a pivot for
  `DRRG: Deep Relational Reasoning Graph Network for Arbitrary Shape Text
  Detection <[https://arxiv.org/abs/2003.07493]>`_.
  
  This code was partially adapted from
  https://github.com/GXYM/DRRG licensed under the MIT license.
  
  Args:
      k_at_hops (tuple(int)): The number of i-hop neighbors, i = 1, 2.
      num_adjacent_linkages (int): The number of linkages when constructing
          adjacent matrix.
      node_geo_feat_len (int): The length of embedded geometric feature
          vector of a text component.
      pooling_scale (float): The spatial scale of rotated RoI-Align.
      pooling_output_size (tuple(int)): The output size of rotated RoI-Align.
      local_graph_thr(float): The threshold for filtering out identical local
          graphs.
docstr: Generate local graphs as GCN input.
  
  Args:
      feat_maps (Tensor): The feature maps to extract the content
          features of text components.
      comp_attribs (ndarray): The text component attributes.
  
  Returns:
      Tuple(local_graphs_node_feat, adjacent_matrices, pivots_knn_inds,
      gt_linkage):
  
      - local_graphs_node_feat (Tensor): The node features of graph.
      - adjacent_matrices (Tensor): The adjacent matrices of local
        graphs.
      - pivots_knn_inds (Tensor): The k-nearest neighbor indices in local
        graph.
      - gt_linkage (Tensor): The surpervision signal of GCN for linkage
        prediction.
docstr_tok: ["Generate","local","graphs","as","GCN","input",".","Args",":","feat_maps","(","Tensor",")",":","The","feature","maps","to","extract","the","content","features","of","text","components",".","comp_attribs","(","ndarray",")",":","The","text","component","attributes",".","Returns",":","Tuple","(","local_graphs_node_feat",",","adjacent_matrices",",","pivots_knn_inds",",","gt_linkage",")",":","-","local_graphs_node_feat","(","Tensor",")",":","The","node","features","of","graph",".","-","adjacent_matrices","(","Tensor",")",":","The","adjacent","matrices","of","local","graphs",".","-","pivots_knn_inds","(","Tensor",")",":","The","k-nearest","neighbor","indices","in","local","graph",".","-","gt_linkage","(","Tensor",")",":","The","surpervision","signal","of","GCN","for","linkage","prediction","."]
code: def __call__(
      self, feat_maps: Tensor, comp_attribs: ndarray
  ) -> Tuple[Tensor, Tensor, Tensor, Tensor]:
      """Generate local graphs as GCN input.
  
      Args:
          feat_maps (Tensor): The feature maps to extract the content
              features of text components.
          comp_attribs (ndarray): The text component attributes.
  
      Returns:
          Tuple(local_graphs_node_feat, adjacent_matrices, pivots_knn_inds,
          gt_linkage):
  
          - local_graphs_node_feat (Tensor): The node features of graph.
          - adjacent_matrices (Tensor): The adjacent matrices of local
            graphs.
          - pivots_knn_inds (Tensor): The k-nearest neighbor indices in local
            graph.
          - gt_linkage (Tensor): The surpervision signal of GCN for linkage
            prediction.
      """
  
      assert isinstance(feat_maps, Tensor)
      assert comp_attribs.ndim == 3
      assert comp_attribs.shape[2] == 8
  
      sorted_dist_inds_batch = []
      local_graph_batch = []
      knn_batch = []
      node_feat_batch = []
      node_label_batch = []
      device = feat_maps.device
  
      for batch_ind in range(comp_attribs.shape[0]):
          num_comps = int(comp_attribs[batch_ind, 0, 0])
          comp_geo_attribs = comp_attribs[batch_ind, :num_comps, 1:7]
          node_labels = comp_attribs[batch_ind, :num_comps, 7].astype(
              np.int32
          )
  
          comp_centers = comp_geo_attribs[:, 0:2]
          distance_matrix = euclidean_distance_matrix(
              comp_centers, comp_centers
          )
  
          batch_id = (
              np.zeros((comp_geo_attribs.shape[0], 1), dtype=np.float32)
              * batch_ind
          )
          comp_geo_attribs[:, -2] = np.clip(
              comp_geo_attribs[:, -2], -1, 1
          )
          angle = np.arccos(comp_geo_attribs[:, -2]) * np.sign(
              comp_geo_attribs[:, -1]
          )
          angle = angle.reshape((-1, 1))
          rotated_rois = np.hstack(
              [batch_id, comp_geo_attribs[:, :-2], angle]
          )
          rois = torch.from_numpy(rotated_rois).to(device)
          content_feats = self.pooling(
              feat_maps[batch_ind].unsqueeze(0), rois
          )
  
          content_feats = content_feats.view(
              content_feats.shape[0], -1
          ).to(feat_maps.device)
          geo_feats = feature_embedding(
              comp_geo_attribs, self.node_geo_feat_dim
          )
          geo_feats = torch.from_numpy(geo_feats).to(device)
          node_feats = torch.cat([content_feats, geo_feats], dim=-1)
  
          sorted_dist_inds = np.argsort(distance_matrix, axis=1)
          pivot_local_graphs, pivot_knns = self.generate_local_graphs(
              sorted_dist_inds, node_labels
          )
  
          node_feat_batch.append(node_feats)
          node_label_batch.append(node_labels)
          local_graph_batch.append(pivot_local_graphs)
          knn_batch.append(pivot_knns)
          sorted_dist_inds_batch.append(sorted_dist_inds)
  
      (
          node_feats,
          adjacent_matrices,
          knn_inds,
          gt_linkage,
      ) = self.generate_gcn_input(
          node_feat_batch,
          node_label_batch,
          local_graph_batch,
          knn_batch,
          sorted_dist_inds_batch,
      )
  
      return node_feats, adjacent_matrices, knn_inds, gt_linkage
  
imports: from typing import Dict, List, Optional, Sequence, Tuple, Union
  import cv2
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.ops import RoIAlignRotated
  from mmengine.model import BaseModule
  from numpy import ndarray
  from torch import Tensor
  from torch.nn import init
  from mmocr.models.textdet.heads import BaseTextDetHead
  from mmocr.registry import MODELS
  from mmocr.structures import TextDetDataSample
  from mmocr.utils import fill_hole
label_desc: Use image node_id 4 for calling the LocalGraphs obj's underlying member method code with example usage: obj.__call__(feat_maps, comp_attribs) and returns: node_feats,  adjacent_matrices,  knn_inds,  gt_linkage