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 themetric_ops
.Parameters: value (dict) – A mapping of the argument name
in the method signature and the variable name in theTrainer
it corresponds to.Note
If the
metric_ops
signature ismetric_ops(self, gen, disc)
then we need to mapgen
togenerator
anddisc
todiscriminator
. In this case we make the following function callmetric.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 pretrainedtorchvision.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 Returns: 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.
Returns: 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 Returns: The output from the classifier.
- classifier (torch.nn.Module, optional) –