code: def calculate_stability_score(
      masks: paddle.Tensor,
      mask_threshold: float,
      threshold_offset: float,
  ) -> paddle.Tensor:
      """
      Computes the stability score for a batch of masks. The stability
      score is the IoU between the binary masks obtained by thresholding
      the predicted mask logits at high and low values.
      """
      # One mask is always contained inside the other.
      # Save memory by preventing unnecessary cast to paddle.int64
      intersections = (
          (masks > (mask_threshold + threshold_offset))
          .cast("int16")
          .sum(-1)
          .cast("int32")
          .sum(-1)
      )
      unions = (
          (masks > (mask_threshold - threshold_offset))
          .cast("int16")
          .sum(-1)
          .cast("int32")
          .sum(-1)
      )
      return intersections / unions
  
imports: import numpy
  import paddle
  import math
  from copy import deepcopy
  from itertools import product
  from typing import Any, Dict, Generator, ItemsView, List, Tuple
label_desc: Use image node_id 7 for calling a global function with example usage: calculate_stability_score(masks, mask_threshold, threshold_offset) and returns: unknown