class_docstr: Class representing a general ImageNet-style hierarchy.
class_docstr_tok: ["Class","representing","a","general","ImageNet-style","hierarchy","."]
docstr: Map nodes to their level within the hierarchy (top-down).
  
  Args:
      graph (networkx graph( : Graph representation of the hierarchy
      root (str) : Hierarchy root.
  
  Return:
      Dictionary mapping node names to integer level.
docstr_tok: ["Map","nodes","to","their","level","within","the","hierarchy","(","top-down",")",".","Args",":","graph","(","networkx","graph","(",":","Graph","representation","of","the","hierarchy","root","(","str",")",":","Hierarchy","root",".","Return",":","Dictionary","mapping","node","names","to","integer","level","."]
code: def _make_level_dict(graph, root):
      """
      Map nodes to their level within the hierarchy (top-down).
  
      Args:
          graph (networkx graph( : Graph representation of the hierarchy
          root (str) : Hierarchy root.
  
      Return:
          Dictionary mapping node names to integer level.
      """
  
      level_dict = {}
      todo = [(root, 0)]  # (node, depth)
      while todo:
          curr = todo
          todo = []
          for n, d in curr:
              if n not in level_dict:
                  level_dict[n] = d
              else:
                  level_dict[n] = max(
                      d, level_dict[n]
                  )  # keep longest path
              for c in graph.successors(n):
                  todo.append((c, d + 1))
  
      return level_dict
  
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 3 for calling the ClassHierarchy obj's underlying member method code with example usage: obj._make_level_dict(graph, root) and returns: level_dict