コード例 #1
0
    def update(self, outputs: torch.Tensor, targets: torch.Tensor) -> float:
        """
        Update metric value with accuracy for new data and return intermediate metric value.

        Args:
            outputs: tensor of outputs
            targets: tensor of true answers

        Returns:
            accuracy metric for outputs and targets
        """
        metric = multilabel_accuracy(outputs=outputs,
                                     targets=targets,
                                     threshold=self.threshold).item()
        super().update(value=metric, num_samples=np.prod(targets.shape))
        return metric
コード例 #2
0
def test_multilabel_accuracy(
    outputs: torch.Tensor,
    targets: torch.Tensor,
    threshold: Union[float, torch.Tensor],
    true_value: float,
):
    """
    Test multilabel accuracy with single and multiple thresholds

    Args:
        outputs: tensor of outputs
        targets: tensor of true answers
        threshold: thresholds for multilabel classification
        true_value: expected metric value
    """
    value = multilabel_accuracy(
        outputs=outputs, targets=targets, threshold=threshold
    ).item()
    assert np.isclose(value, true_value)