Shortcuts

InceptionScore#

class ignite.metrics.InceptionScore(num_features=None, feature_extractor=None, output_transform=<function InceptionScore.<lambda>>, device=device(type='cpu'))[source]#

Calculates Inception Score.

IS(G)=exp(1Ni=1NDKL(p(yx(i)p^(y))))\text{IS(G)} = \exp(\frac{1}{N}\sum_{i=1}^{N} D_{KL} (p(y|x^{(i)} \parallel \hat{p}(y))))

where p(yx)p(y|x) is the conditional probability of image being the given object and p(y)p(y) is the marginal probability that the given image is real, G refers to the generated image and DKLD_{KL} refers to KL Divergence of the above mentioned probabilities.

More details can be found in Barratt et al. 2018.

Parameters
  • num_features (Optional[int]) – number of features predicted by the model or number of classes of the model. Default value is 1000.

  • feature_extractor (Optional[torch.nn.modules.module.Module]) – a torch Module for predicting the probabilities from the input data. It returns a tensor of shape (batch_size, num_features). If neither num_features nor feature_extractor are defined, by default we use an ImageNet pretrained Inception Model. If only num_features is defined but feature_extractor is not defined, feature_extractor is assigned Identity Function. Please note that the class object will be implicitly converted to device mentioned in the device argument.

  • output_transform (Callable) – a callable that is used to transform the Engine’s process_function’s output into the form expected by the metric. This can be useful if, for example, you have a multi-output model and you want to compute the metric with respect to one of the outputs. By default, metrics require the output as y_pred.

  • device (Union[str, torch.device]) – specifies which device updates are accumulated on. Setting the metric’s device to be the same as your update arguments ensures the update method is non-blocking. By default, CPU.

Return type

None

Note

The default Inception model requires the torchvision module to be installed.

Examples

from ignite.metric.gan import InceptionScore
import torch

images = torch.rand(10, 3, 299, 299)

m = InceptionScore()
m.update(images)
print(m.compute())

New in version 0.4.6.

Methods

compute

Computes the metric based on it's accumulated state.

reset

Resets the metric to it's initial state.

update

Updates the metric's state using the passed batch output.

compute()[source]#

Computes the metric based on it’s accumulated state.

By default, this is called at the end of each epoch.

Returns

the actual quantity of interest. However, if a Mapping is returned, it will be (shallow) flattened into engine.state.metrics when completed() is called.

Return type

Any

Raises

NotComputableError – raised when the metric cannot be computed.

reset()[source]#

Resets the metric to it’s initial state.

By default, this is called at the start of each epoch.

Return type

None

update(output)[source]#

Updates the metric’s state using the passed batch output.

By default, this is called once for each batch.

Parameters

output (torch.Tensor) – the is the output from the engine’s process function.

Return type

None