(class_ids, logits, targets)
return height_to_accuracy
Accuracy as a function of the height of class' the lowest common ancestor.

  This is only applicable to 2-way ImageNet episodes. Given the class set of
  each episode, we find the corresponding 2 leaves of the ImageNet graph and
  compute the lowest common ancestor of those leaves. Its height is computed as
  the maximum over the length of the paths from that node to each of the two
  leaves. This height is the estimate of fine-grainedness. Intuitively, the
  larger the height, the more coarse-grained the episode's classification task.

  Args:
    class_ids: A list containing a np.array per episode that contains the two
      class id's chosen for the episode's binary classification task. These id's
      are ints in the range between 1 and the total number of classes.
    logits: A list containing a np.array per episode. The shape of an episode's
      array is [size of test set, way].
    targets: A list containing a np.array per episode. The shape of an episode's
      array is [size of test set]. This contains integers in the range from 0 to
      the way of the episode.

  Returns:
    height_to_accuracy: A dict that maps each 'observed' height to a list that
      contains the accuracies obtained for different episodes with that height.

  Raises:
    ValueError: There should have been exactly 2 elements in the list of each
      episode's class id's.
Accuracy as a function of the height of class' the lowest common ancestor.
Accuracy as a function of the height of class the lowest common ancestor .
def get_height_to_accuracy(class_ids, logits, targets):
  """Accuracy as a function of the height of class' the lowest common ancestor.

  This is only applicable to 2-way ImageNet episodes. Given the class set of
  each episode, we find the corresponding 2 leaves of the ImageNet graph and
  compute the lowest common ancestor of those leaves. Its height is computed as
  the maximum over the length of the paths from that node to each of the two
  leaves. This height is the estimate of fine-grainedness. Intuitively, the
  larger the height, the more coarse-grained the episode's classification task.

  Args:
    class_ids: A list containing a np.array per episode that contains the two
      class id's chosen for the episode's binary classification task. These id's
      are ints in the range between 1 and the total number of classes.
    logits: A list containing a np.array per episode. The shape of an episode's
      array is [size of test set, way].
    targets: A list containing a np.array per episode. The shape of an episode's
      array is [size of test set]. This contains integers in the range from 0 to
      the way of the episode.

  Returns:
    height_to_accuracy: A dict that maps each 'observed' height to a list that
      contains the accuracies obtained for different episodes with that height.

  Raises:
    ValueError: There should have been exactly 2 elements in the list of each
      episode's class id's.
  """
  height_to_accuracy = collections.defaultdict(list)
  for episode_num, episode_class_ids in enumerate(class_ids):
    if len(episode_class_ids) != 2:
      raise ValueError('There should have been exactly 2 elements in the list '
                       "of each episode's class id's.")
    # Get the Synsets corresponding to the class id's episode_class_ids.
    episode_synsets = get_synsets_from_class_ids(episode_class_ids)
    assert len(episode_synsets) == 2, ('Fine- vs coarse- grained analysis '
                                       'should be restricted to binary tasks.')
    # Compute the height of the lowest common ancestor of the episode's Synsets.
    _, height = imagenet_spec.get_lowest_common_ancestor(
        episode_synsets[0], episode_synsets[1])
    # Compute the accuracy of the episode.
    episode_logits = logits[episode_num]
    episode_targets = targets[episode_num]
    episode_acc = compute_episode_accuracy(episode_logits, episode_targets)
    height_to_accuracy[height].append(episode_acc)
  return height_to_accuracy
def get_height_to_accuracy ( class_ids , logits , targets ) : height_to_accuracy = collections . defaultdict ( list ) for episode_num , episode_class_ids in enumerate ( class_ids ) : if len ( episode_class_ids ) != 2 : raise ValueError ( 'There should have been exactly 2 elements in the list ' "of each episode's class id's." ) # Get the Synsets corresponding to the class id's episode_class_ids. episode_synsets = get_synsets_from_class_ids ( episode_class_ids ) assert len ( episode_synsets ) == 2 , ( 'Fine- vs coarse- grained analysis ' 'should be restricted to binary tasks.' ) # Compute the height of the lowest common ancestor of the episode's Synsets. _ , height = imagenet_spec . get_lowest_common_ancestor ( episode_synsets [ 0 ] , episode_synsets [ 1 ] ) # Compute the accuracy of the episode. episode_logits = logits [ episode_num ] episode_targets = targets [ episode_num ] episode_acc = compute_episode_accuracy ( episode_logits , episode_targets ) height_to_accuracy [ height ] . append ( episode_acc ) return height_to_accuracy