(unique_class_ids, shots, dataset_spec)
return class_props
Computes the proportion of the total number of examples appearing as shots.

  Args:
    unique_class_ids: A 1D int Tensor of unique class IDs.
    shots: A 1D Tensor of the number of shots for each class in
      `unique_class_ids`.
    dataset_spec: A DatasetSpecification that contains informations about the
      class labels in `unique_class_ids`.

  Returns:
    A 1D Tensor with the proportion of examples appearing as shots per class in
    `unique_class_ids`, normalized by the total number of examples for each
    class in the dataset according to `dataset_spec`.
Computes the proportion of the total number of examples appearing as shots.
Computes the proportion of the total number of examples appearing as shots .
def compute_class_proportions(unique_class_ids, shots, dataset_spec):
  """Computes the proportion of the total number of examples appearing as shots.

  Args:
    unique_class_ids: A 1D int Tensor of unique class IDs.
    shots: A 1D Tensor of the number of shots for each class in
      `unique_class_ids`.
    dataset_spec: A DatasetSpecification that contains informations about the
      class labels in `unique_class_ids`.

  Returns:
    A 1D Tensor with the proportion of examples appearing as shots per class in
    `unique_class_ids`, normalized by the total number of examples for each
    class in the dataset according to `dataset_spec`.
  """
  # Get the total number of examples of each class in the dataset.
  num_dataset_classes = len(dataset_spec.images_per_class)
  num_images_per_class = [
      dataset_spec.get_total_images_per_class(class_id)
      for class_id in range(num_dataset_classes)
  ]

  # Make sure that `unique_class_ids` are valid indices of
  # `num_images_per_class`. This is important since `tf.gather` will fail
  # silently and return zeros otherwise.
  num_classes = tf.shape(num_images_per_class)[0]
  check_valid_inds_op = tf.assert_less(unique_class_ids, num_classes)
  with tf.control_dependencies([check_valid_inds_op]):
    # Get the total number of examples of each class that is in the episode.
    num_images_per_class = tf.gather(num_images_per_class,
                                     unique_class_ids)  # [?, ]

  # Get the proportions of examples of each class that appear in the episode.
  class_props = tf.truediv(shots, num_images_per_class)
  return class_props
def compute_class_proportions ( unique_class_ids , shots , dataset_spec ) : # Get the total number of examples of each class in the dataset. num_dataset_classes = len ( dataset_spec . images_per_class ) num_images_per_class = [ dataset_spec . get_total_images_per_class ( class_id ) for class_id in range ( num_dataset_classes ) ] # Make sure that `unique_class_ids` are valid indices of # `num_images_per_class`. This is important since `tf.gather` will fail # silently and return zeros otherwise. num_classes = tf . shape ( num_images_per_class ) [ 0 ] check_valid_inds_op = tf . assert_less ( unique_class_ids , num_classes ) with tf . control_dependencies ( [ check_valid_inds_op ] ) : # Get the total number of examples of each class that is in the episode. num_images_per_class = tf . gather ( num_images_per_class , unique_class_ids ) # [?, ] # Get the proportions of examples of each class that appear in the episode. class_props = tf . truediv ( shots , num_images_per_class ) return class_props