def compute(self) -> torch.Tensor:
        """Compute the maximum F1 score across all thresholds.

        Computes F1 scores at different thresholds using the precision-recall
        curve. Stores the threshold that achieves maximum F1 score in the
        ``threshold`` attribute.

        Returns:
            torch.Tensor: Maximum F1 score value.
        """
        precision: torch.Tensor
        recall: torch.Tensor
        thresholds: torch.Tensor

        precision, recall, thresholds = self.precision_recall_curve.compute()
        f1_score = (2 * precision * recall) / (precision + recall + 1e-10)
        self.threshold = thresholds.item() if thresholds.ndim == 0 else thresholds[torch.argmax(f1_score)]
        return torch.max(f1_score)
Compute the maximum F1 score across all thresholds.

        Computes F1 scores at different thresholds using the precision-recall
        curve. Stores the threshold that achieves maximum F1 score in the
        ``threshold`` attribute.

        Returns:
            torch.Tensor: Maximum F1 score value.
        
src/anomalib/metrics/f1_score.py