---
title: Inception Score
description: >-
  Calculate the Inception Score (IS) which is used to access how realistic
  generated images are.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/image/inception_score'
---
# Inception Score {#inception-score}

## Module Interface {#module-interface}

### `class torchmetrics.image.inception.InceptionScore(feature='logits_unbiased', splits=10, normalize=False, **kwargs)` {#torchmetrics.image.inception.InceptionScore}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/inception.py#L35-L221)

Calculate the Inception Score (IS) which is used to access how realistic generated images are.

```math
IS = exp(\mathbb{E}_x KL(p(y | x ) || p(y)))
```

where $`KL(p(y | x) || p(y))`$ is the KL divergence between the conditional distribution $`p(y|x)`$ and the marginal distribution $`p(y)`$. Both the conditional and marginal distribution is calculated from features extracted from the images. The score is calculated on random splits of the images such that both a mean and standard deviation of the score are returned. The metric was originally proposed in [inception ref1](https://arxiv.org/abs/1606.03498).

Using the default feature extraction (Inception v3 using the original weights from [inception ref2](https://arxiv.org/abs/1706.08500)), the input is expected to be mini-batches of 3-channel RGB images of shape `(3xHxW)`. If argument `normalize` is `True` images are expected to be dtype `float` and have values in the `[0,1]` range, else if `normalize` is set to `False` images are expected to have dtype uint8 and take values in the `[0, 255]` range. All images will be resized to 299 x 299 which is the size of the original training data.

Hint

Using this metric with the default feature extractor requires that `torch-fidelity` is installed. Either install as `pip install torchmetrics[image]` or `pip install torch-fidelity`

As input to `forward` and `update` the metric accepts the following input

*   `imgs` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): tensor with images feed to the feature extractor
    

As output of forward and compute the metric returns the following output

*   `inception_mean` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): float scalar tensor with mean inception score over subsets
    
*   `inception_std` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): float scalar tensor with standard deviation of inception score over subsets
    

Parameters:

*   **feature** (`Union`\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)"), [`Module`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module "(in PyTorch v2.15)")\]) –
    
    Either an str, integer or `nn.Module`:
    
    *   an str or integer will indicate the inceptionv3 feature layer to choose. Can be one of the following: ‘logits\_unbiased’, 64, 192, 768, 2048
        
    *   an `nn.Module` for using a custom feature extractor. Expects that its forward method returns an `(N,d)` matrix where `N` is the batch size and `d` is the feature size.
        
    
*   **splits** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – integer determining how many splits the inception score calculation should be split among
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Raises:

*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `feature` is set to an `str` or `int` and `torch-fidelity` is not installed
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `feature` is set to an `str` or `int` and not one of `('logits_unbiased', 64, 192, 768, 2048)`
    
*   [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError "(in Python v3.15)") – If `feature` is not an `str`, `int` or `torch.nn.Module`
    

Example

```python
>>> from torch import rand
>>> from torchmetrics.image.inception import InceptionScore
>>> inception = InceptionScore()
>>> # generate some images
>>> imgs = torch.randint(0, 255, (100, 3, 299, 299), dtype=torch.uint8)
>>> inception.update(imgs)
>>> inception.compute()
(tensor(1.0549), tensor(0.0121))
```

#### `plot(val=None, ax=None)` {#torchmetrics.image.inception.InceptionScore.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/image/inception.py#L179-L221)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> # Example plotting a single value
>>> import torch
>>> from torchmetrics.image.inception import InceptionScore
>>> metric = InceptionScore()
>>> metric.update(torch.randint(0, 255, (50, 3, 299, 299), dtype=torch.uint8))
>>> fig_, ax_ = metric.plot()  # the returned plot only shows the mean value by default
```

```python
>>> # Example plotting multiple values
>>> import torch
>>> from torchmetrics.image.inception import InceptionScore
>>> metric = InceptionScore()
>>> values = [ ]
>>> for _ in range(3):
...     # we index by 0 such that only the mean value is plotted
...     values.append(metric(torch.randint(0, 255, (50, 3, 299, 299), dtype=torch.uint8))[0])
>>> fig_, ax_ = metric.plot(values)
```

---

**Navigation**

- Parent: [Image](/docs/torchmetrics/1.9.0/image.md)
