FID#
- class ignite.metrics.FID(num_features=None, feature_extractor=None, output_transform=<function FID.<lambda>>, device=device(type='cpu'))[source]#
 Calculates Frechet Inception Distance.
where and refer to the mean and covariance of the train data and and refer to the mean and covariance of the test data.
More details can be found in Heusel et al. 2002
In addition, a faster and online computation approach can be found in Chen et al. 2014
Remark:
This implementation is inspired by pytorch_fid package which can be found here
Note
The default Inception model requires the torchvision module to be installed. FID also requires scipy library for matrix square root calculations.
- Parameters
 num_features (Optional[int]) – number of features predicted by the model or the reduced feature vector of the image. Default value is 2048.
feature_extractor (Optional[Module]) – a torch Module for extracting the features from the input data. It returns a tensor of shape (batch_size, num_features). If neither
num_featuresnorfeature_extractorare defined, by default we use an ImageNet pretrained Inception Model. If onlynum_featuresis defined butfeature_extractoris not defined,feature_extractoris assigned Identity Function. Please note that the model will be implicitly converted to device mentioned in thedeviceargument.output_transform (Callable) – a callable that is used to transform the
Engine’sprocess_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, y)or{'y_pred': y_pred, 'y': y}.device (Union[str, device]) – specifies which device updates are accumulated on. Setting the metric’s device to be the same as your
updatearguments ensures theupdatemethod is non-blocking. By default, CPU.
Examples
import torch from ignite.metric.gan import FID y_pred, y = torch.rand(10, 3, 299, 299), torch.rand(10, 3, 299, 299) m = FID() m.update((y_pred, y)) print(m.compute())
New in version 0.4.6.
Methods
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.
- 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
Mappingis returned, it will be (shallow) flattened into engine.state.metrics whencompleted()is called. - Return type
 Any
- Raises
 NotComputableError – raised when the metric cannot be computed.