code: def normalize_adj_torch(adj):
      # print(adj.size())
      if len(adj.size()) == 4:
          new_r = torch.zeros(adj.size()).type_as(adj)
          for i in range(adj.size(1)):
              adj_item = adj[0, i]
              rowsum = adj_item.sum(1)
              d_inv_sqrt = rowsum.pow_(-0.5)
              d_inv_sqrt[torch.isnan(d_inv_sqrt)] = 0
              d_mat_inv_sqrt = torch.diag(d_inv_sqrt)
              r = torch.matmul(
                  torch.matmul(d_mat_inv_sqrt, adj_item), d_mat_inv_sqrt
              )
              new_r[0, i, ...] = r
          return new_r
      rowsum = adj.sum(1)
      d_inv_sqrt = rowsum.pow_(-0.5)
      d_inv_sqrt[torch.isnan(d_inv_sqrt)] = 0
      d_mat_inv_sqrt = torch.diag(d_inv_sqrt)
      r = torch.matmul(
          torch.matmul(d_mat_inv_sqrt, adj), d_mat_inv_sqrt
      )
      return r
  
file_path: insightface/reconstruction/ostec/external/graphonomy/FaceHairMask/graph.py
imports: import torch
  import numpy
  import networkx
  import scipy.sparse
label_desc: Use image node_id 4 for calling a global function with example usage: normalize_adj_torch(adj) and returns: r, new_r