(embeddings, labels)
return prototypes
Computes class prototypes over features.

  Flattens and reshapes the features if they are not already flattened.
  Args:
    embeddings: Tensor of examples of shape [num_examples, embedding_size] or
      [num_examples, spatial_dim, spatial_dim n_features].
    labels: Tensor of one-hot encoded labels of shape [num_examples,
      num_classes].

  Returns:
    prototypes: Tensor of class prototypes of shape [num_classes,
      embedding_size].
Computes class prototypes over features.
Computes class prototypes over features .
def compute_prototypes(embeddings, labels):
  """Computes class prototypes over features.

  Flattens and reshapes the features if they are not already flattened.
  Args:
    embeddings: Tensor of examples of shape [num_examples, embedding_size] or
      [num_examples, spatial_dim, spatial_dim n_features].
    labels: Tensor of one-hot encoded labels of shape [num_examples,
      num_classes].

  Returns:
    prototypes: Tensor of class prototypes of shape [num_classes,
      embedding_size].
  """
  if len(embeddings.shape) > 2:
    feature_shape = embeddings.shape.as_list()[1:]
    n_images = tf.shape(embeddings)[0]
    n_classes = tf.shape(labels)[-1]

    vectorized_embedding = tf.reshape(embeddings, [n_images, -1])
    vectorized_prototypes = _compute_prototypes(vectorized_embedding, labels)
    prototypes = tf.reshape(vectorized_prototypes, [n_classes] + feature_shape)
  else:
    prototypes = _compute_prototypes(embeddings, labels)

  return prototypes
def compute_prototypes ( embeddings , labels ) : if len ( embeddings . shape ) > 2 : feature_shape = embeddings . shape . as_list ( ) [ 1 : ] n_images = tf . shape ( embeddings ) [ 0 ] n_classes = tf . shape ( labels ) [ - 1 ] vectorized_embedding = tf . reshape ( embeddings , [ n_images , - 1 ] ) vectorized_prototypes = _compute_prototypes ( vectorized_embedding , labels ) prototypes = tf . reshape ( vectorized_prototypes , [ n_classes ] + feature_shape ) else : prototypes = _compute_prototypes ( embeddings , labels ) return prototypes