class_docstr: Class for generating datasets from ImageNet superclasses.
class_docstr_tok: ["Class","for","generating","datasets","from","ImageNet","superclasses","."]
docstr: Obtain a dataset composed of ImageNet superclasses with a desired
  set of properties. 
  (Optional) By specifying a split, one can parition the subclasses
  into two disjoint datasets (with the same superclasses).
  
  Args:
      level (int): Depth in hierarchy (from root node)
      Nsubclasses (int): Minimum number of subclasses per superclass
      balanced (bool): Whether or not the dataset should be
                       balanced over superclasses
      split ("good"/"bad"/"rand"/None): If None, superclasses are
                       not partitioned into two disjoint datasets.
                       If not None, determines whether the subclass
                       partitioning should be more or less 
                       adversarial or random
      rng (RandomState): Random number generator
  
  Returns:
      superclasses (list): WordNet IDs of superclasses
      subclass_splits (tuple): Tuple entries correspond to the source 
                               and target domains respectively. A 
                               tuple entry is a list, where each 
                               element is a list of subclasses to 
                               be included in a given superclass in
                               that domain. If split is None,
                               the second tuple element is empty.
      label_map (dict): Map from (super)class number to superclass name 
docstr_tok: ["Obtain","a","dataset","composed","of","ImageNet","superclasses","with","a","desired","set","of","properties",".","(","Optional",")","By","specifying","a","split",",","one","can","parition","the","subclasses","into","two","disjoint","datasets","(","with","the","same","superclasses",")",".","Args",":","level","(","int",")",":","Depth","in","hierarchy","(","from","root","node",")","Nsubclasses","(","int",")",":","Minimum","number","of","subclasses","per","superclass","balanced","(","bool",")",":","Whether","or","not","the","dataset","should","be","balanced","over","superclasses","split","(","``","good","''","\/","''","bad","''","\/","''","rand","''","\/None",")",":","If","None",",","superclasses","are","not","partitioned","into","two","disjoint","datasets",".","If","not","None",",","determines","whether","the","subclass","partitioning","should","be","more","or","less","adversarial","or","random","rng","(","RandomState",")",":","Random","number","generator","Returns",":","superclasses","(","list",")",":","WordNet","IDs","of","superclasses","subclass_splits","(","tuple",")",":","Tuple","entries","correspond","to","the","source","and","target","domains","respectively",".","A","tuple","entry","is","a","list",",","where","each","element","is","a","list","of","subclasses","to","be","included","in","a","given","superclass","in","that","domain",".","If","split","is","None",",","the","second","tuple","element","is","empty",".","label_map","(","dict",")",":","Map","from","(","super",")","class","number","to","superclass","name"]
code: def get_superclasses(
      self,
      level,
      Nsubclasses=None,
      split=None,
      ancestor=None,
      balanced=True,
      random_seed=2,
      verbose=False,
  ):
      """
      Obtain a dataset composed of ImageNet superclasses with a desired
      set of properties.
      (Optional) By specifying a split, one can parition the subclasses
      into two disjoint datasets (with the same superclasses).
  
      Args:
          level (int): Depth in hierarchy (from root node)
          Nsubclasses (int): Minimum number of subclasses per superclass
          balanced (bool): Whether or not the dataset should be
                           balanced over superclasses
          split ("good"/"bad"/"rand"/None): If None, superclasses are
                           not partitioned into two disjoint datasets.
                           If not None, determines whether the subclass
                           partitioning should be more or less
                           adversarial or random
          rng (RandomState): Random number generator
  
      Returns:
          superclasses (list): WordNet IDs of superclasses
          subclass_splits (tuple): Tuple entries correspond to the source
                                   and target domains respectively. A
                                   tuple entry is a list, where each
                                   element is a list of subclasses to
                                   be included in a given superclass in
                                   that domain. If split is None,
                                   the second tuple element is empty.
          label_map (dict): Map from (super)class number to superclass name
      """
  
      rng = np.random.RandomState(random_seed)
      hierarchy = self.hierarchy
  
      # Identify superclasses at this level
      rel_nodes = sorted(
          list(hierarchy.get_nodes_at_level(level, ancestor=ancestor))
      )
      if verbose:
          hierarchy.print_node_info(rel_nodes)
  
      # Count number of subclasses
      in_desc = []
      for n in rel_nodes:
          dcurr = self.hierarchy.leaves_reachable(n)
          in_desc.append(sorted(list(dcurr)))
      min_desc = np.min([len(d) for d in in_desc])
      assert min_desc > 0
  
      # Determine number of subclasses to include per superclass
      if Nsubclasses is None:
          if balanced:
              Nsubclasses = min_desc
              if Nsubclasses % 2 != 0:
                  Nsubclasses = max(2, Nsubclasses - 1)
          else:
              Nsubclasses = 1 if split is None else 2
  
      # Find superclasses that have sufficient subclasses
      superclass_idx = [
          i
          for i in range(len(rel_nodes))
          if len(in_desc[i]) >= Nsubclasses
      ]
      superclasses, all_subclasses = [
          rel_nodes[i] for i in superclass_idx
      ], [in_desc[i] for i in superclass_idx]
  
      # Superclass names
      label_map = {}
      for ri, r in enumerate(superclasses):
          label_map[ri] = self.hierarchy.node_name(r)
  
      if split is None:
          if balanced:
              Ns = [Nsubclasses] * len(all_subclasses)
          else:
              Ns = [len(d) for d in all_subclasses]
          wnids = [
              list(rng.choice(d, n, replace=False))
              for n, d in zip(Ns, all_subclasses)
          ]
          subclass_ranges = [
              [self.hierarchy.LEAF_ID_TO_NUM[w] for w in c]
              for c in wnids
          ]
          subclass_splits = (subclass_ranges, [])
      else:
          subclass_splits = ([], [])
          for sci, sc in enumerate(sorted(superclasses)):
              class_tup = self.split_superclass(
                  sc,
                  Nsubclasses=Nsubclasses,
                  balanced=balanced,
                  split_type=split,
                  rng=rng,
              )
              subclass_splits[0].append(class_tup[0])
              subclass_splits[1].append(class_tup[1])
  
      return superclasses, subclass_splits, label_map
  
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 BreedsDatasetGenerator obj's underlying member method code with example usage: obj.get_superclasses(level, Nsubclasses, split, ancestor, balanced, random_seed, verbose) and returns: superclasses,  subclass_splits,  label_map