- class ignite.metrics.InceptionScore(num_features=None, feature_extractor=None, output_transform=<function InceptionScore.<lambda>>, device=device(type='cpu'))#
Calculates Inception Score.
where is the conditional probability of image being the given object and is the marginal probability that the given image is real, G refers to the generated image and refers to KL Divergence of the above mentioned probabilities.
More details can be found in Barratt et al. 2018.
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
feature_extractorare defined, by default we use an ImageNet pretrained Inception Model. If only
num_featuresis defined but
feature_extractoris not defined,
feature_extractoris assigned Identity Function. Please note that the class object will be implicitly converted to device mentioned in the
output_transform (Callable) – a callable that is used to transform the
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
device (Union[str, torch.device]) – specifies which device updates are accumulated on. Setting the metric’s device to be the same as your
updatearguments ensures the
updatemethod is non-blocking. By default, CPU.
- Return type
The default Inception model requires the torchvision module to be installed.
from collections import OrderedDict import torch from torch import nn, optim from ignite.engine import * from ignite.handlers import * from ignite.metrics import * from ignite.utils import * from ignite.contrib.metrics.regression import * from ignite.contrib.metrics import * # create default evaluator for doctests def eval_step(engine, batch): return batch default_evaluator = Engine(eval_step) # create default optimizer for doctests param_tensor = torch.zeros(, requires_grad=True) default_optimizer = torch.optim.SGD([param_tensor], lr=0.1) # create default trainer for doctests # as handlers could be attached to the trainer, # each test must define his own trainer using `.. testsetup:` def get_default_trainer(): def train_step(engine, batch): return batch return Engine(train_step) # create default model for doctests default_model = nn.Sequential(OrderedDict([ ('base', nn.Linear(4, 2)), ('fc', nn.Linear(2, 1)) ])) manual_seed(666)
metric = InceptionScore() metric.attach(default_evaluator, "is") y = torch.rand(10, 3, 299, 299) state = default_evaluator.run([y]) print(state.metrics["is"])
metric = InceptionScore(num_features=1, feature_extractor=default_model) metric.attach(default_evaluator, "is") y = torch.zeros(10, 4) state = default_evaluator.run([y]) print(state.metrics["is"])
New in version 0.4.6.
Computes the metric based on it's accumulated state.
Resets the metric to it's initial state.
Updates the metric's state using the passed batch output.
Computes the metric based on it’s accumulated state.
By default, this is called at the end of each epoch.
- Return type
NotComputableError – raised when the metric cannot be computed.
Resets the metric to it’s initial state.
By default, this is called at the start of each epoch.
- Return type