Inception Score¶
Module Interface¶
- class torchmetrics.image.inception.InceptionScore(feature='logits_unbiased', splits=10, compute_on_step=None, **kwargs)[source]
Calculates the Inception Score (IS) which is used to access how realistic generated images are. It is defined as

where
is the KL divergence between the conditional distribution
and the margianl distribution
. 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 [1].Using the default feature extraction (Inception v3 using the original weights from [2]), the input is expected to be mini-batches of 3-channel RGB images of shape (3 x H x W) with dtype uint8. All images will be resized to 299 x 299 which is the size of the original training data.
Note
using this metric with the default feature extractor requires that
torch-fidelityis installed. Either install aspip install torchmetrics[image]orpip install torch-fidelityNote
the
forwardmethod can be used butcompute_on_stepis disabled by default (oppesit of all other metrics) as this metric does not really make sense to calculate on a single batch. This means that by defaultforwardwill just callupdateunderneat.- Parameters
feature¶ (
Union[str,int,Module]) –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.Modulefor using a custom feature extractor. Expects that its forward method returns an[N,d]matrix whereNis the batch size anddis the feature size.
splits¶ (
int) – integer determining how many splits the inception score calculation should be split amongcompute_on_step¶ (
Optional[bool]) –Forward only calls
update()and returns None if this is set to False.Deprecated since version v0.8: Argument has no use anymore and will be removed v0.9.
kwargs¶ (
Dict[str,Any]) – Additional keyword arguments, see Advanced metric settings for more info.
References
[1] Improved Techniques for Training GANs Tim Salimans, Ian Goodfellow, Wojciech Zaremba, Vicki Cheung, Alec Radford, Xi Chen https://arxiv.org/abs/1606.03498
[2] GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium, Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler, Sepp Hochreiter https://arxiv.org/abs/1706.08500
- Raises
ValueError – If
featureis set to anstrorintandtorch-fidelityis not installedValueError – If
featureis set to anstrorintand not one of['logits_unbiased', 64, 192, 768, 2048]TypeError – If
featureis not anstr,intortorch.nn.Module
Example
>>> import torch >>> _ = torch.manual_seed(123) >>> 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.0544), tensor(0.0117))
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- compute()[source]
Override this method to compute the final metric value from state variables synchronized across the distributed backend.