Skip to content

confidence_weights

ConfidenceWeights

Bases: torch.nn.Module

Returns the max value along each row of the input, followed by an optional normalization function. The output of this can be used to weight classification losses by the "confidence" of the predictions.

Source code in pytorch_adapt\layers\confidence_weights.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class ConfidenceWeights(torch.nn.Module):
    """
    Returns the max value along each row of the input,
    followed by an optional normalization function.
    The output of this can be used to weight
    classification losses by the "confidence" of the predictions.
    """

    def __init__(self, normalizer: Callable[[torch.Tensor], torch.Tensor] = None):
        """
        Arguments:
            normalizer: A callable for normalizing
                (e.g. min-max normalization) the weights.
                If ```None```, then no normalization is used.
        """

        super().__init__()
        self.normalizer = c_f.default(normalizer, NoNormalizer())

    def forward(self, preds):
        """"""
        return self.normalizer(torch.max(preds, dim=1)[0])

__init__(normalizer=None)

Parameters:

Name Type Description Default
normalizer Callable[[torch.Tensor], torch.Tensor]

A callable for normalizing (e.g. min-max normalization) the weights. If None, then no normalization is used.

None
Source code in pytorch_adapt\layers\confidence_weights.py
17
18
19
20
21
22
23
24
25
26
def __init__(self, normalizer: Callable[[torch.Tensor], torch.Tensor] = None):
    """
    Arguments:
        normalizer: A callable for normalizing
            (e.g. min-max normalization) the weights.
            If ```None```, then no normalization is used.
    """

    super().__init__()
    self.normalizer = c_f.default(normalizer, NoNormalizer())