code: def _compute_stability_score_pt(
      masks: "torch.Tensor",
      mask_threshold: float,
      stability_score_offset: int,
  ):
      # One mask is always contained inside the other.
      # Save memory by preventing unnecesary cast to torch.int64
      intersections = (
          (masks > (mask_threshold + stability_score_offset))
          .sum(-1, dtype=torch.int16)
          .sum(-1, dtype=torch.int32)
      )
      unions = (
          (masks > (mask_threshold - stability_score_offset))
          .sum(-1, dtype=torch.int16)
          .sum(-1, dtype=torch.int32)
      )
      stability_scores = intersections / unions
      return stability_scores
  
imports: import math
  from copy import deepcopy
  from itertools import product
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
  from ...image_transforms import convert_to_rgb, pad, resize, to_channel_dimension_format
  from ...image_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, ChannelDimension, ImageInput, PILImageResampling, get_image_size, infer_channel_dimension_format, is_scaled_image, make_list_of_images, to_numpy_array, valid_images
  from ...utils import TensorType, is_tf_available, is_torch_available, is_torchvision_available, logging, requires_backends
label_desc: Use image node_id 1 for calling a global function with example usage: _compute_stability_score_pt(masks, mask_threshold, stability_score_offset) and returns: stability_scores