code: def f_score(
      gt,
      pr,
      beta=1,
      class_weights=1,
      class_indexes=None,
      smooth=SMOOTH,
      per_image=False,
      threshold=None,
      **kwargs,
  ):
      r"""The F-score (Dice coefficient) can be interpreted as a weighted average of the precision and recall,
      where an F-score reaches its best value at 1 and worst score at 0.
      The relative contribution of ``precision`` and ``recall`` to the F1-score are equal.
      The formula for the F score is:
  
      .. math:: F_\beta(precision, recall) = (1 + \beta^2) \frac{precision \cdot recall}
          {\beta^2 \cdot precision + recall}
  
      The formula in terms of *Type I* and *Type II* errors:
  
      .. math:: F_\beta(A, B) = \frac{(1 + \beta^2) TP} {(1 + \beta^2) TP + \beta^2 FN + FP}
  
  
      where:
          TP - true positive;
          FP - false positive;
          FN - false negative;
  
      Args:
          gt: ground truth 4D keras tensor (B, H, W, C) or (B, C, H, W)
          pr: prediction 4D keras tensor (B, H, W, C) or (B, C, H, W)
          class_weights: 1. or list of class weights, len(weights) = C
          class_indexes: Optional integer or list of integers, classes to consider, if ``None`` all classes are used.
          beta: f-score coefficient
          smooth: value to avoid division by zero
          per_image: if ``True``, metric is calculated as mean over images in batch (B),
              else over whole batch
          threshold: value to round predictions (use ``>`` comparison), if ``None`` prediction will not be round
  
      Returns:
          F-score in range [0, 1]
  
      """
  
      backend = kwargs["backend"]
  
      gt, pr = gather_channels(gt, pr, indexes=class_indexes, **kwargs)
      pr = round_if_needed(pr, threshold, **kwargs)
      axes = get_reduce_axes(per_image, **kwargs)
  
      # calculate score
      tp = backend.sum(gt * pr, axis=axes)
      fp = backend.sum(pr, axis=axes) - tp
      fn = backend.sum(gt, axis=axes) - tp
  
      score = ((1 + beta**2) * tp + smooth) / (
          (1 + beta**2) * tp + beta**2 * fn + fp + smooth
      )
      score = average(score, per_image, class_weights, **kwargs)
  
      return score
  
file_path: segmentation_models/segmentation_models/base/functional.py
label_desc: Use image node_id 7 for calling a global function with example usage: f_score(gt, pr, beta, class_weights, class_indexes, smooth, per_image, threshold) and returns: score