code: def _evaluate(self, Gs, Gs_kwargs, num_gpus):
      minibatch_size = num_gpus * self.minibatch_per_gpu
      feature_net = misc.load_pkl(
          "https://drive.google.com/uc?id=1MzY4MFpZzE-mNS26pzhYlWN-4vMm2ytu"
      )  # vgg16.pkl
  
      # Calculate features for reals.
      cache_file = self._get_cache_file_for_reals(
          num_images=self.num_images
      )
      os.makedirs(os.path.dirname(cache_file), exist_ok=True)
      if os.path.isfile(cache_file):
          ref_features = misc.load_pkl(cache_file)
      else:
          ref_features = np.empty(
              [self.num_images, feature_net.output_shape[1]],
              dtype=np.float32,
          )
          for idx, images in enumerate(
              self._iterate_reals(minibatch_size=minibatch_size)
          ):
              begin = idx * minibatch_size
              end = min(begin + minibatch_size, self.num_images)
              ref_features[begin:end] = feature_net.run(
                  images[: end - begin],
                  num_gpus=num_gpus,
                  assume_frozen=True,
              )
              if end == self.num_images:
                  break
          misc.save_pkl(ref_features, cache_file)
  
      # Construct TensorFlow graph.
      result_expr = []
      for gpu_idx in range(num_gpus):
          with tf.device("/gpu:%d" % gpu_idx):
              Gs_clone = Gs.clone()
              feature_net_clone = feature_net.clone()
              latents = tf.random_normal(
                  [self.minibatch_per_gpu] + Gs_clone.input_shape[1:]
              )
              labels = self._get_random_labels_tf(
                  self.minibatch_per_gpu
              )
              images = Gs_clone.get_output_for(
                  latents, labels, **Gs_kwargs
              )
              images = tflib.convert_images_to_uint8(images)
              result_expr.append(
                  feature_net_clone.get_output_for(images)
              )
  
      # Calculate features for fakes.
      eval_features = np.empty(
          [self.num_images, feature_net.output_shape[1]],
          dtype=np.float32,
      )
      for begin in range(0, self.num_images, minibatch_size):
          self._report_progress(begin, self.num_images)
          end = min(begin + minibatch_size, self.num_images)
          eval_features[begin:end] = np.concatenate(
              tflib.run(result_expr), axis=0
          )[: end - begin]
  
      # Calculate precision and recall.
      state = knn_precision_recall_features(
          ref_features=ref_features,
          eval_features=eval_features,
          feature_net=feature_net,
          nhood_sizes=[self.nhood_size],
          row_batch_size=self.row_batch_size,
          col_batch_size=self.row_batch_size,
          num_gpus=num_gpus,
      )
      self._report_result(state.knn_precision[0], suffix="_precision")
      self._report_result(state.knn_recall[0], suffix="_recall")
  
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 2 for calling the PR obj's underlying member method code with example usage: obj._evaluate(Gs, Gs_kwargs, num_gpus) without return types