code: def _create_segmentations(
      seg_data, image_id, classes_map, dataset_dir
  ):
      all_label_ids = seg_data["all_ids"]
      relevant_ids = seg_data["relevant_ids"]
      df = seg_data["df"]
  
      if image_id not in all_label_ids:
          return None
  
      if image_id not in relevant_ids:
          return fol.Detections()
  
      def _make_label(row):
          # MaskPath,ImageID,LabelName,BoxID,BoxXMin,BoxXMax,BoxYMin,BoxYMax,
          #   PredictedIoU,Clicks
  
          mask_path = row["MaskPath"]
          label = classes_map[row["LabelName"]]
          xmin = float(row["BoxXMin"])
          xmax = float(row["BoxXMax"])
          ymin = float(row["BoxYMin"])
          ymax = float(row["BoxYMax"])
  
          # Convert to [top-left-x, top-left-y, width, height]
          bbox = [xmin, ymin, xmax - xmin, ymax - ymin]
  
          # Load boolean mask
          mask_path = os.path.join(
              dataset_dir,
              "labels",
              "masks",
              image_id[0].upper(),
              mask_path,
          )
          if not os.path.isfile(mask_path):
              msg = "Segmentation file %s does not exist", mask_path
              warnings.warn(msg)
              return None
  
          rgb_mask = foui.read(mask_path)
          mask = etai.rgb_to_gray(rgb_mask) > 122
          h, w = mask.shape
          cropped_mask = mask[
              int(ymin * h) : int(ymax * h),
              int(xmin * w) : int(xmax * w),
          ]
  
          return fol.Detection(
              bounding_box=bbox, label=label, mask=cropped_mask
          )
  
      matching_df = _get_dataframe_rows(df, image_id)
      segs = [_make_label(row[1]) for row in matching_df.iterrows()]
      segs = [s for s in segs if s is not None]
      return fol.Detections(detections=segs)
  
imports: from collections import defaultdict
  import csv
  from glob import glob
  import logging
  import os
  import random
  import warnings
  import pandas
  import eta.core.image
  import eta.core.serial
  import eta.core.utils
  import eta.core.web
  import fiftyone
  import fiftyone.core.fields
  import fiftyone.core.labels
  import fiftyone.utils.aws
  import fiftyone.utils.data
  import fiftyone.utils.image
label_desc: Use image node_id 28 for calling a global function with example usage: _create_segmentations(seg_data, image_id, classes_map, dataset_dir) and returns: fol, None, fol, fol, None