class_docstr: Class for representing ImageNet/WordNet hierarchy. 
class_docstr_tok: ["Class","for","representing","ImageNet\/WordNet","hierarchy","."]
docstr: Args:
      ds_path (str) : Path to ImageNet dataset
      ds_info_path (str) : Path to supplementary files for the ImageNet dataset 
                           ('wordnet.is_a.txt', 'words.txt' and 'imagenet_class_index.json')
                           which can be obtained from http://image-net.org/download-API.
docstr_tok: ["Args",":","ds_path","(","str",")",":","Path","to","ImageNet","dataset","ds_info_path","(","str",")",":","Path","to","supplementary","files","for","the","ImageNet","dataset","(","'wordnet.is_a.txt","'",",","'words.txt","'","and","'imagenet_class_index.json","'",")","which","can","be","obtained","from","http",":","\/\/image-net.org\/download-API","."]
code: def __init__(self, ds_path, ds_info_path):
      """
      Args:
          ds_path (str) : Path to ImageNet dataset
          ds_info_path (str) : Path to supplementary files for the ImageNet dataset
                               ('wordnet.is_a.txt', 'words.txt' and 'imagenet_class_index.json')
                               which can be obtained from http://image-net.org/download-API.
  
      """
      self.tree = {}
  
      ret = self.load_imagenet_info(ds_path, ds_info_path)
      (
          self.in_wnids,
          self.wnid_to_name,
          self.wnid_to_num,
          self.num_to_name,
      ) = ret
  
      with open(
          os.path.join(ds_info_path, "wordnet.is_a.txt"), "r"
      ) as f:
          for line in f.readlines():
              parent_wnid, child_wnid = line.strip("\n").split(" ")
              parentNode = self.get_node(parent_wnid)
              childNode = self.get_node(child_wnid)
              parentNode.add_child(childNode)
  
      for wnid in self.in_wnids:
          self.tree[wnid].descendant_count_in = 0
          self.tree[wnid].class_num = self.wnid_to_num[wnid]
  
      for wnid in self.in_wnids:
          node = self.tree[wnid]
          while node.parent_wnid is not None:
              self.tree[node.parent_wnid].descendant_count_in += 1
              self.tree[node.parent_wnid].descendants_all.update(
                  node.descendants_all
              )
              self.tree[node.parent_wnid].descendants_all.add(node.wnid)
              node = self.tree[node.parent_wnid]
  
      del_nodes = [
          wnid
          for wnid in self.tree
          if (
              self.tree[wnid].descendant_count_in == 0
              and self.tree[wnid].class_num == -1
          )
      ]
      for d in del_nodes:
          self.tree.pop(d, None)
  
      assert all(
          [
              k.descendant_count_in > 0 or k.class_num != -1
              for k in self.tree.values()
          ]
      )
  
      self.wnid_sorted = sorted(
          sorted(
              [
                  (k, v.descendant_count_in, len(v.descendants_all))
                  for k, v in self.tree.items()
              ],
              key=lambda x: x[2],
              reverse=True,
          ),
          key=lambda x: x[1],
          reverse=True,
      )
  
file_path: robustness/robustness/tools/imagenet_helpers.py
imports: import os
  import numpy
  import json
  from itertools import product
label_desc: Use image node_id 1 to create a new ImageNetHierarchy object  with example: obj = ImageNetHierarchy(ds_path, ds_info_path)