Skip to content

torchmetrics_validator

TorchmetricsValidator

Bases: BaseValidator

Source code in pytorch_adapt\validators\torchmetrics_validator.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class TorchmetricsValidator(BaseValidator):
    def __init__(self, layer="preds", torchmetric_kwargs=None, **kwargs):
        """
        Arguments:
            layer: The name of the layer to pass into the accuracy function.
                For example, ```"preds"``` refers to the softmaxed logits.
            torchmetric_kwargs: A dictionary of keyword arguments to be
                passed into the
                [torchmetrics accuracy function](https://torchmetrics.readthedocs.io/en/latest/references/functional.html#accuracy-func).
        """
        super().__init__(**kwargs)
        self.layer = layer
        self.torchmetric_kwargs = c_f.default(torchmetric_kwargs, {})

    def compute_score(self, src_val):
        return self.accuracy_fn(
            src_val[self.layer], src_val["labels"], **self.torchmetric_kwargs
        ).item()

    @property
    @abstractmethod
    def accuracy_fn(self):
        pass

__init__(layer='preds', torchmetric_kwargs=None, **kwargs)

Parameters:

Name Type Description Default
layer

The name of the layer to pass into the accuracy function. For example, "preds" refers to the softmaxed logits.

'preds'
torchmetric_kwargs

A dictionary of keyword arguments to be passed into the torchmetrics accuracy function.

None
Source code in pytorch_adapt\validators\torchmetrics_validator.py
 8
 9
10
11
12
13
14
15
16
17
18
19
def __init__(self, layer="preds", torchmetric_kwargs=None, **kwargs):
    """
    Arguments:
        layer: The name of the layer to pass into the accuracy function.
            For example, ```"preds"``` refers to the softmaxed logits.
        torchmetric_kwargs: A dictionary of keyword arguments to be
            passed into the
            [torchmetrics accuracy function](https://torchmetrics.readthedocs.io/en/latest/references/functional.html#accuracy-func).
    """
    super().__init__(**kwargs)
    self.layer = layer
    self.torchmetric_kwargs = c_f.default(torchmetric_kwargs, {})