# torchgan.metrics¶

This subpackage provides various metrics that are available to judge the performance of GANs. Currently available metrics are:

## Metric¶

### EvaluationMetric¶

class torchgan.metrics.EvaluationMetric[source]

Base class for all Evaluation Metrics

calculate_score(x)[source]

Subclasses must override this function and provide their own score calculation.

Raises: NotImplementedError – If the subclass doesn’t override this function.
metric_ops(generator, discriminator, **kwargs)[source]

Subclasses must override this function and provide their own metric evaluation ops.

Raises: NotImplementedError – If the subclass doesn’t override this function.
preprocess(x)[source]

Subclasses must override this function and provide their own preprocessing pipeline.

Raises: NotImplementedError – If the subclass doesn’t override this function.
set_arg_map(value)[source]

Updates the arg_map for passing a different value to the metric_ops.

Parameters: value (dict) – A mapping of the argument name in the method signature and the variable name in the Trainer it corresponds to.

Note

If the metric_ops signature is metric_ops(self, gen, disc) then we need to map gen to generator and disc to discriminator. In this case we make the following function call metric.set_arg_map({"gen": "generator", "disc": "discriminator"}).

## Classifier Score¶

class torchgan.metrics.ClassifierScore(classifier=None, transform=None, sample_size=1)[source]

Computes the Classifier Score of a Model. Also popularly known as the Inception Score. The classifier can be any model. It also supports models outside of torchvision models. For more details on how to use custom trained models look up the tutorials.

Parameters: classifier (torch.nn.Module, optional) – The model to be used as a base to compute the classifier score. If None is passed the pretrained torchvision.models.inception_v3 is used. Note Ensure that the classifier is on the same device as the Trainer to avoid sudden crash. transform (torchvision.transforms, optional) – Transformations applied to the image before feeding it to the classifier. Look up the documentation of the torchvision models for this transforms. sample_size (int) – Batch Size for calculation of Classifier Score.
calculate_score(x)[source]

Computes the Inception Score for the Input.

Parameters: x (torch.Tensor) – Image in tensor format The Inception Score.
metric_ops(generator, device)[source]

Defines the set of operations necessary to compute the ClassifierScore.

Parameters: generator (torchgan.models.Generator) – The generator which needs to be evaluated. device (torch.device) – Device on which the generator is present. The Classifier Score (scalar quantity)
preprocess(x)[source]

Preprocessor for the Classifier Score. It transforms the image as per the transform requirements and feeds it to the classifier.

Parameters: x (torch.Tensor) – Image in tensor format The output from the classifier.