class_docstr: Anomaly Score Threshold.
  
  This class computes/stores the threshold that determines the anomalous label
  given anomaly scores. If the threshold method is ``manual``, the class only
  stores the manual threshold values.
  
  If the threshold method is ``adaptive``, the class initially computes the
  adaptive threshold to find the optimal f1_score and stores the computed
  adaptive threshold value.
docstr: Compute the threshold that yields 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 threshold that yields 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
  
      if not any(1 in batch for batch in self.target):
          warnings.warn(
              "The validation set does not contain any anomalous images. As a result, the adaptive threshold will "
              "take the value of the highest anomaly score observed in the normal validation images, which may lead "
              "to poor predictions. For a more reliable adaptive threshold computation, please add some anomalous "
              "images to the validation set."
          )
  
      precision, recall, thresholds = super().compute()
      f1_score = (2 * precision * recall) / (precision + recall + 1e-10)
      if thresholds.dim() == 0:
          # special case where recall is 1.0 even for the highest threshold.
          # In this case 'thresholds' will be scalar.
          self.value = thresholds
      else:
          self.value = thresholds[torch.argmax(f1_score)]
      return self.value
  
file_path: anomalib/src/anomalib/utils/metrics/anomaly_score_threshold.py
imports: from __future__ import annotations
  import warnings
  import torch
  from torch import Tensor
  from torchmetrics import PrecisionRecallCurve
label_desc: Use image node_id 2 for calling the AnomalyScoreThreshold obj's underlying member method code with example usage: obj.compute() and returns: self