class_docstr: Class representing a general ImageNet-style hierarchy.
class_docstr_tok: ["Class","representing","a","general","ImageNet-style","hierarchy","."]
docstr: Obtain networkx representation of class hierarchy.
  
  Args:
      nodes [str] : List of node names to traverse upwards.
      edges [(str, str)] : Tuples of parent-child pairs.
  
  Return:
      networkx representation of the graph.
docstr_tok: ["Obtain","networkx","representation","of","class","hierarchy",".","Args",":","nodes","[","str","]",":","List","of","node","names","to","traverse","upwards",".","edges","[","(","str",",","str",")","]",":","Tuples","of","parent-child","pairs",".","Return",":","networkx","representation","of","the","graph","."]
code: def _make_parent_graph(nodes, edges):
      """
      Obtain networkx representation of class hierarchy.
  
      Args:
          nodes [str] : List of node names to traverse upwards.
          edges [(str, str)] : Tuples of parent-child pairs.
  
      Return:
          networkx representation of the graph.
      """
  
      # create full graph
      full_graph_dir = {}
      for p, c in edges:
          if p not in full_graph_dir:
              full_graph_dir[p] = {c: 1}
          else:
              full_graph_dir[p].update({c: 1})
  
      FG = nx.DiGraph(full_graph_dir)
  
      # perform backward BFS to get the relevant graph
      graph_dir = {}
      todo = [
          n for n in nodes if n in FG.nodes()
      ]  # skip nodes not in graph
      while todo:
          curr = todo
          todo = []
          for w in curr:
              for p in FG.predecessors(w):
                  if p not in graph_dir:
                      graph_dir[p] = {w: 1}
                  else:
                      graph_dir[p].update({w: 1})
                  todo.append(p)
          todo = set(todo)
  
      return nx.DiGraph(graph_dir)
  
imports: import sys, os
  import json
  import numpy
  import pandas
  import urllib
  from collections import OrderedDict, Counter
  import operator
  import networkx
  from ..datasets import DATASETS
label_desc: Use image node_id 2 for calling the ClassHierarchy obj's underlying member method code with example usage: obj._make_parent_graph(nodes, edges) and returns: nx