class_docstr: Optimal F1 Metric.
  
  Compute the optimal F1 score at the adaptive threshold, based on the F1 metric of the true labels and the
  predicted anomaly scores.
docstr: Compute the value of the optimal F1 score.
  
  Compute the F1 scores while varying the threshold. Store the optimal
  threshold as attribute and return the maximum value of the F1 score.
  
  Returns:
      Value of the F1 score at the optimal threshold.
code: def compute(self) -> Tensor:
      """Compute the value of the optimal F1 score.
  
      Compute the F1 scores while varying the threshold. Store the optimal
      threshold as attribute and return the maximum value of the F1 score.
  
      Returns:
          Value of the F1 score at the optimal threshold.
      """
      precision: Tensor
      recall: Tensor
      thresholds: Tensor
  
      (
          precision,
          recall,
          thresholds,
      ) = self.precision_recall_curve.compute()
      f1_score = (2 * precision * recall) / (precision + recall + 1e-10)
      self.threshold = thresholds[torch.argmax(f1_score)]
      optimal_f1_score = torch.max(f1_score)
      return optimal_f1_score
  
file_path: anomalib/src/anomalib/utils/metrics/optimal_f1.py
imports: import warnings
  import torch
  from torch import Tensor
  from torchmetrics import Metric, PrecisionRecallCurve
label_desc: Use image node_id 3 for calling the OptimalF1 obj's underlying member method code with example usage: obj.compute() and returns: optimal_f1_score