class_docstr: Finds an estimate for the manifold of given feature vectors.
class_docstr_tok: ["Finds","an","estimate","for","the","manifold","of","given","feature","vectors","."]
docstr: Find an estimate of the manifold of given feature vectors.
docstr_tok: ["Find","an","estimate","of","the","manifold","of","given","feature","vectors","."]
code: def __init__(
      self,
      distance_block,
      features,
      row_batch_size,
      col_batch_size,
      nhood_sizes,
      clamp_to_percentile=None,
  ):
      """Find an estimate of the manifold of given feature vectors."""
      num_images = features.shape[0]
      self.nhood_sizes = nhood_sizes
      self.num_nhoods = len(nhood_sizes)
      self.row_batch_size = row_batch_size
      self.col_batch_size = col_batch_size
      self._ref_features = features
      self._distance_block = distance_block
  
      # Estimate manifold of features by calculating distances to kth nearest neighbor of each sample.
      self.D = np.zeros([num_images, self.num_nhoods], dtype=np.float16)
      distance_batch = np.zeros(
          [row_batch_size, num_images], dtype=np.float16
      )
      seq = np.arange(max(self.nhood_sizes) + 1, dtype=np.int32)
  
      for begin1 in range(0, num_images, row_batch_size):
          end1 = min(begin1 + row_batch_size, num_images)
          row_batch = features[begin1:end1]
  
          for begin2 in range(0, num_images, col_batch_size):
              end2 = min(begin2 + col_batch_size, num_images)
              col_batch = features[begin2:end2]
  
              # Compute distances between batches.
              distance_batch[
                  0 : end1 - begin1, begin2:end2
              ] = self._distance_block.pairwise_distances(
                  row_batch, col_batch
              )
  
          # Find the kth nearest neighbor from the current batch.
          self.D[begin1:end1, :] = np.partition(
              distance_batch[0 : end1 - begin1, :], seq, axis=1
          )[:, self.nhood_sizes]
  
      if clamp_to_percentile is not None:
          max_distances = np.percentile(
              self.D, clamp_to_percentile, axis=0
          )
          self.D[self.D > max_distances] = 0
  
file_path: insightface/reconstruction/ostec/external/stylegan2/metrics/precision_recall.py
imports: import os
  import numpy
  import tensorflow
  import dnnlib
  import dnnlib.tflib
  from metrics import metric_base
  from training import misc
label_desc: Use image node_id 1 to create a new ManifoldEstimator object  with example: obj = ManifoldEstimator(distance_block, features, row_batch_size, col_batch_size, nhood_sizes, clamp_to_percentile)