code: def convert_segmentation_to_rle(segmentation):
      """
      Converts given segmentation map of shape (height, width) to the run-length encoding (RLE) format.
  
      Args:
          segmentation (`torch.Tensor` or `numpy.array`):
              A segmentation map of shape `(height, width)` where each value denotes a segment or class id.
      Returns:
          `List[List]`: A list of lists, where each list is the run-length encoding of a segment / class id.
      """
      segment_ids = torch.unique(segmentation)
  
      run_length_encodings = []
      for idx in segment_ids:
          mask = torch.where(segmentation == idx, 1, 0)
          rle = binary_mask_to_rle(mask)
          run_length_encodings.append(rle)
  
      return run_length_encodings
  
imports: import pathlib
  import warnings
  from typing import Dict, List, Optional, Set, Tuple, Union
  import numpy
  from PIL import Image
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import ImageFeatureExtractionMixin, is_torch_tensor
  from ...utils import TensorType, is_torch_available, logging
label_desc: Use image node_id 6 for calling a global function with example usage: convert_segmentation_to_rle(segmentation) and returns: run_length_encodings