Missed TensorFlow World? Check out the recap. Learn more


View source on GitHub

Kernel "classifier" distance for evaluating a generative model.


  • tf.contrib.gan.eval.classifier_metrics.kernel_classifier_distance_from_activations

This methods computes the kernel classifier distance from activations of real images and generated images. This can be used independently of the kernel_classifier_distance() method, especially in the case of using large batches during evaluation where we would like to precompute all of the activations before computing the classifier distance, or if we want to compute multiple metrics based on the same images.

This technique is described in detail in https://arxiv.org/abs/1801.01401. Given two distributions P and Q of activations, this function calculates

E_{X, X' ~ P}[k(X, X')] + E_{Y, Y' ~ Q}[k(Y, Y')]
  - 2 E_{X ~ P, Y ~ Q}[k(X, Y)]

where k is the polynomial kernel

k(x, y) = ( x^T y / dimension + 1 )^3.

This captures how different the distributions of real and generated images' visual features are. Like the Frechet distance (and unlike the Inception score), this is a true distance and incorporates information about the target images. Unlike the Frechet score, this function computes an unbiased and asymptotically normal estimator, which makes comparing estimates across models much more intuitive.

The estimator used takes time quadratic in max_block_size. Larger values of max_block_size will decrease the variance of the estimator but increase the computational cost. This differs slightly from the estimator used by the original paper; it is the block estimator of https://arxiv.org/abs/1307.1954.

NOTE: the blocking code assumes that real_activations and generated_activations are both in random order. If either is sorted in a meaningful order, the estimator will behave poorly.


  • real_activations: 2D Tensor containing activations of real data. Shape is [batch_size, activation_size].
  • generated_activations: 2D Tensor containing activations of generated data. Shape is [batch_size, activation_size].
  • max_block_size: integer, default 1024. The distance estimator splits samples into blocks for computational efficiency. Larger values are more computationally expensive but decrease the variance of the distance estimate.
  • dtype: If not None, coerce activations to this dtype before computations.


The Kernel Inception Distance. A floating-point scalar of the same type as the output of the activations.