AI Logic

Evaluation Metrics

Inception Score

Updated:

Computing the Inception Score. Left: generated images pass through the Inception model to give per-image class probabilities p(y|x); the KL divergence to p(y), the average of p(y|x) over all images, is averaged and exponentiated. Right: an example with 4 classes and 4 images, where clear and diverse generations give IS 2.22, clear but all-same-class generations (mode collapse) give 1.00, and blurry generations give 1.01

Background and overview

The Inception Score (IS) is an evaluation metric that passes generated images through a pretrained image classification model (Inception) and combines into a single number whether each image clearly shows an object and whether the model generates many different kinds of objects overall. It is at least 1, and a higher value means a better generative model.

IS=exp⁡(Ex KL(p(y∣x) ∥ p(y)))\mathrm{IS} = \exp\left( \mathbb{E}_{x} \, \mathrm{KL}\left( p(y \mid x) \,\Vert\, p(y) \right) \right)

xx is a generated image, p(y∣x)p(y \mid x) is the class probability the Inception model outputs for image xx, and p(y)p(y) is the class probability averaged over all generated images (the marginal distribution). The KL divergence measures the difference between two distributions.

IS was proposed in 2016 by Salimans et al. in a paper collecting techniques for stabilizing GAN training (Improved Techniques for Training GANs). GANs have no way to compare performance by the value of the training objective, so the paper first asked people to distinguish real images from generated ones. However, human evaluation varied with the task design and the motivation of the annotators, and when annotators were given feedback on their mistakes, they learned to spot flaws and the results changed substantially. IS was therefore designed as a metric that can be computed automatically in place of human evaluation and that correlates well with human judgment.

Definition and computation

IS is computed in the following steps.

  1. Generate many images with the generative model (50,000 in the paper).
  2. Pass each image through an Inception model trained on ImageNet (of the GoogLeNet (Inception) family) to get the probabilities p(y∣x)p(y \mid x) over 1000 classes.
  3. Average p(y∣x)p(y \mid x) over all images to estimate the marginal distribution p(y)p(y).
p^(y)=1N∑i=1Np(y∣x(i))\hat{p}(y) = \frac{1}{N} \sum_{i=1}^{N} p(y \mid x^{(i)})
  1. Compute KL(p(y∣x(i))∥p^(y))\mathrm{KL}(p(y \mid x^{(i)}) \Vert \hat{p}(y)) for each image and average over all images.
  2. Take the exp of the average. According to the paper, the exp is there to make values easier to compare.

This formula combines two desirable properties into one.

  • Each image is clear: if an image shows a meaningful object, the Inception model is confident in a single class, so the entropy of p(y∣x)p(y \mid x) is low.
  • The set is diverse: if the model generates many kinds of images, the averaged p(y)p(y) spreads over many classes, so its entropy is high.

As Barratt and Sharma (2018) showed, the average KL equals the mutual information between images and classes, so log⁡IS=H(y)−H(y∣x)\log \mathrm{IS} = H(y) - H(y \mid x). H(y)H(y) is the entropy of p(y)p(y), and H(y∣x)H(y \mid x) is the average entropy of p(y∣x)p(y \mid x). As a result, IS ranges from 1 up to the number of classes (1000 for ImageNet).

The right side of the figure at the top shows an example with 4 classes and 4 images. When each image clearly shows a different class, p(y)p(y) spreads evenly over the 4 classes and IS is 2.22. When every image shows the same class (mode collapse), p(y∣x)p(y \mid x) equals p(y)p(y), the KL becomes 0, and IS is 1.00. When every image is blurry and no class is clear, IS is 1.01, almost the minimum.

As an analogy, IS is like showing generated images one at a time to someone who knows an animal encyclopedia well. The score is higher when they can say "this is a dog" without hesitation for each image, and when dogs, cats, ships and many other things appear across the set. Conversely, the score is low if every image is the same dog (not diverse) or if they cannot tell what is in the image (not clear).

What it measures and its limitations

IS measures whether, as seen by an ImageNet classification model, the generated images clearly show objects and span many different classes. Its distinctive feature is that it can be computed from generated images alone, without real images.

IS also has the following limitations.

  • It does not compare with real images: since it uses no real-image statistics, images of a different kind from the training data still score high as long as the Inception model classifies them confidently. FID was proposed to fix this drawback by comparing with the feature distribution of real images.
  • It ignores diversity within a class: even if the model produces only one kind of image per class, the score is high as long as all classes are covered. A model that memorizes and reproduces the training data also scores high, so Barratt and Sharma recommend showing by other means that the model is not overfitting.
  • The value depends on the Inception weights: Barratt and Sharma showed that two Inception-v3 models with almost the same classification accuracy, with weights from Keras and from PyTorch, give IS values that differ by 11.5% on the same CIFAR-10 images.
  • It does not suit data other than ImageNet: when CIFAR-10 images are passed through the Inception model, the top classes include ones that do not exist in CIFAR-10, such as moving van and thresher. Barratt and Sharma recommend using IS only for ImageNet generative models, and for other data using a classifier trained on that data.
  • It loses its meaning when optimized directly: the paper itself warns that directly maximizing IS produces adversarial examples. Barratt and Sharma showed that slightly perturbing WGAN outputs, without changing how realistic they look, yields images with an IS of 900.15.

IS values are comparable only when computed with the same Inception weights, the same implementation, and the same number of images and splits. The commonly used implementation divides 50,000 images into 10 splits, computes IS for each split, and reports the mean and standard deviation. According to Barratt and Sharma, merely increasing the number of splits from 1 to 200 lowers the IS of the same images from 9.91 to 9.09. In addition, the paper's released code used an Inception model with 1008 class outputs rather than 1000. When comparing with prior work, use the same implementation and state the settings.

Validation in the original paper

The paper computed IS on 50,000 images generated by GANs trained on CIFAR-10, and checked how the value changed when the paper's techniques were removed one at a time (Table 3).

ModelIS (± standard deviation)
Real images (CIFAR-10)11.24 ± 0.12
Model with all of the paper's techniques8.09 ± 0.07
Generator's virtual batch normalization replaced with batch normalization7.54 ± 0.07
No labels, with historical averaging of parameters added6.86 ± 0.06
One-sided label smoothing removed6.83 ± 0.06
No labels4.36 ± 0.04
Minibatch discrimination removed3.87 ± 0.03

Real images got the highest value, and models whose generations had even partially collapsed to a few modes got low values. The paper states that IS agreed well with the authors' subjective judgment of image quality.

The paper also checked the link to human judgment. When real images and generated images from the best model were mixed half and half and Amazon Mechanical Turk annotators were asked to tell them apart, they were correct 78.7% of the time. Restricting the generated images to the top 1% by IS lowered this rate to 71.4%. In other words, images with a higher IS were also harder for people to distinguish from real ones.

The paper cautions that IS should be used as "a rough guide to evaluate models that were trained via some independent criterion". Using IS as a training objective or selecting models by IS alone is not the intended use.

Where it is used

IS is mainly used in the following settings.

  • Comparing image generation models: in GAN research, IS on CIFAR-10 and ImageNet has been widely reported to compare models such as DCGAN and WGAN. Today it is common to report it alongside FID.
  • Class-conditional generation: for models that generate images of specified ImageNet classes, the assumptions behind IS (clear ImageNet classes per image and diverse classes overall) apply directly.
  • Comparing with prior work: many older papers report only IS, so it is sometimes computed to compare under the same conditions.

Comparison with similar metrics

The table compares IS with other metrics used to evaluate image generation from the same viewpoints.

MetricCompares with real images?What it measuresDirectionMain constraints
Inception ScoreNoClass confidence per image and class diversity overallHigher is betterIgnores within-class diversity. Weak meaning outside ImageNet
FIDYes (mean and covariance of features)Distance between the distributions of generated and real imagesLower is betterDepends on the number of images and preprocessing
Human evaluationJudged by peopleWhether images can be told apart from real ones, visual naturalnessDepends on the evaluation designTakes time and money, and results change with the design

Rough guidelines for choosing:

  • Evaluating a new image generation model: use FID as the main metric. Because it compares with real images, images unlike the training data and a lack of diversity also show up in the value.
  • Comparing with prior work on ImageNet class-conditional generation: in addition to FID, report IS computed with the same implementation as prior work.
  • Images of a different kind from ImageNet (faces, bedrooms, medical images, etc.): do not use IS, or replace the classifier with one trained on that data.

PyTorch example

Show code
python
import torch
import torch.nn.functional as F


def inception_score(probs, splits=10):
  """IS = exp(E_x KL(p(y|x) || p(y))) from Salimans et al. (2016).
  probs: p(y|x) of shape (num_images, num_classes) (softmax outputs of the Inception model).
  Following the common implementation, splits the images into `splits` groups, computes IS per group, and returns the mean and standard deviation."""
  scores = []
  for part in probs.chunk(splits, dim=0):
    py = part.mean(dim=0, keepdim=True)                          # estimate of the marginal p(y)
    kl = (part * (torch.log(part + 1e-12) - torch.log(py + 1e-12))).sum(dim=1)
    scores.append(torch.exp(kl.mean()))
  scores = torch.stack(scores)
  return scores.mean(), scores.std()


# Computing p(y|x): Inception-v3 trained on ImageNet (torchvision). Use eval() for evaluation
from torchvision.models import inception_v3, Inception_V3_Weights

net = inception_v3(weights=Inception_V3_Weights.IMAGENET1K_V1).eval()
generator.eval()
probs = []
with torch.no_grad():
  for _ in range(num_batches):                       # 50,000 images in the paper
    z = torch.randn(batch_size, latent_dim)
    x = generator(z)                                 # e.g. (B, 3, H, W) in [-1, 1]
    x = F.interpolate((x + 1) / 2, size=(299, 299), mode="bilinear", align_corners=False)
    x = (x - torch.tensor([0.485, 0.456, 0.406]).view(1, 3, 1, 1)) / torch.tensor([0.229, 0.224, 0.225]).view(1, 3, 1, 1)
    probs.append(F.softmax(net(x), dim=1))
mean, std = inception_score(torch.cat(probs))

# With torchmetrics (requires torch-fidelity). Uses an Inception matching the original TensorFlow version;
# with normalize=False it takes uint8 images in [0, 255]. compute() returns (mean, std)
from torchmetrics.image.inception import InceptionScore

metric = InceptionScore(splits=10, normalize=False)
metric.update(fake_images_uint8)                     # (B, 3, H, W), uint8
print(metric.compute())

FAQ

Q. What Inception Score counts as good?
A.

There is no fixed threshold, because the value changes with the dataset, the Inception weights, the implementation and the number of splits. On CIFAR-10 in the paper, real images scored 11.24 and the paper's best model scored 8.09. Judge a value by placing it next to the scores of real images and existing models computed under the same conditions.

Q. What is the maximum Inception Score?
A.

The number of classes: 1000 for an ImageNet Inception model. Since log⁡IS=H(y)−H(y∣x)\log \mathrm{IS} = H(y) - H(y \mid x), the maximum is reached when every image is confidently assigned to one class (H(y∣x)=0H(y \mid x) = 0) and the classes appear uniformly over the whole set (H(y)=log⁡1000H(y) = \log 1000). However, values reported for real image generation are far smaller, and a value near the maximum does not necessarily mean the images look real.

Q. How do the Inception Score and FID differ?
A.

IS is computed from generated images alone and does not compare with real images. FID compares the feature distributions of real and generated images. As a result, FID also reflects cases where the model generates images of a different kind from the training data or lacks diversity within a class. Higher IS is better, while lower FID is better.

References

  1. Salimans, T., Goodfellow, I., Zaremba, W., Cheung, V., Radford, A., & Chen, X. (2016). Improved Techniques for Training GANs. NeurIPS 2016. arXiv:1606.03498.
  2. Barratt, S., & Sharma, R. (2018). A Note on the Inception Score. arXiv:1801.01973.
  3. Heusel, M., Ramsauer, H., Unterthiner, T., Nessler, B., & Hochreiter, S. (2017). GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium. NeurIPS 2017. arXiv:1706.08500.
  4. Lightning AI. torchmetrics.image.InceptionScore (API reference).