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.
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
dim – int, which dimension to apply the argmax transform over