Transforms

Transforms are usefull for adjusting the target and predictions before the metrics are calculated. For example in the classification case if the output of a neural network is the class probabilities/logits i.e. tensor with shape (N,C), the ArgmaxTransform(dim=-1) can be used to transform into labels before any metrics are calculated.

To create your own transformation, you can simply inherent from the base class Transform and implement your own __init__ and forward methods. For an example, here is the implementation of the ArgmaxTransform:

class ArgmaxTransform(Transform):
    def __init__(self, dim=-1):
        self.dim = dim

    def forward(self, target, pred):
        return target, pred.argmax(dim=self.dim)

The forward method of a transform is alwarys expected to take in two arguments (target, pred) and return two variables, the transformed target and pred.

Transform

class pytorch_metrics.transforms.Transform

ComposeTransforms

class pytorch_metrics.transforms.ComposeTransforms(*transforms)
Compose multiple transforms into one single transform. The transforms

will be compose in a sequential matter.

Parameters

transforms – sequence of transforms to compose into one.

DefaultTransform

class pytorch_metrics.transforms.DefaultTransform

Default transform that does nothing to the target and predictions

ArgmaxTransform

class pytorch_metrics.transforms.ArgmaxTransform(dim=-1)

Applies the argmax transform to the predictions. Often used to transform probabilities/logits into labels in multiclass tasks.

Parameters

dimint, which dimension to apply the argmax transform over

RoundTransform

class pytorch_metrics.transforms.RoundTransform(dim=-1)

Applies a round transform to the predictions. Often used to transform the output from sigmoid activations into labels in binary tasks

Parameters

dimint, which dimension to apply the round transform over

ROCTransform

class pytorch_metrics.transforms.ROCTransform(line)