code: def convert_to_lightly_prediction(filename: str, seg_map: np.ndarray):
      """Converts a segmentation map of shape W x H x C to Lightly format."""
      seg_map_argmax = np.argmax(seg_map, axis=-1)
  
      prediction = {"file_name": filename, "predictions": []}
      for category_id in np.unique(seg_map_argmax):
          rle = binary_to_rle(seg_map_argmax == category_id)
          logits = np.mean(
              seg_map[seg_map_argmax == category_id], axis=0
          )
          assert np.argmax(logits) == category_id
          probabilities = np.exp(logits) / np.sum(np.exp(logits))
          assert abs(np.sum(probabilities) - 1.0) < 1e-6
  
          prediction["predictions"].append(
              {
                  "category_id": int(category_id),
                  "segmentation": [int(r) for r in rle],
                  "score": float(probabilities[category_id]),
                  "probabilities": [float(p) for p in probabilities],
              }
          )
  
      return prediction
  
imports: import json
  import os
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: convert_to_lightly_prediction(filename, seg_map) and returns: prediction