code: def binary_mask_to_rle(mask):
      """
      Args:
      Converts given binary mask of shape (height, width) to the run-length encoding (RLE) format.
          mask (`torch.Tensor` or `numpy.array`):
              A binary mask tensor of shape `(height, width)` where 0 denotes background and 1 denotes the target
              segment_id or class_id.
      Returns:
          `List`: Run-length encoded list of the binary mask. Refer to COCO API for more information about the RLE
          format.
      """
      if is_torch_tensor(mask):
          mask = mask.numpy()
  
      pixels = mask.flatten()
      pixels = np.concatenate([[0], pixels, [0]])
      runs = np.where(pixels[1:] != pixels[:-1])[0] + 1
      runs[1::2] -= runs[::2]
      return [x for x in runs]
  
imports: from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union
  import numpy
  from PIL import Image
  from transformers.image_utils import PILImageResampling
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor
  from ...utils import TensorType, is_torch_available, logging
label_desc: Use image node_id 1 for calling a global function with example usage: binary_mask_to_rle(mask) and returns: unknown