code: def objects_to_segmentations(
      sample_collection,
      in_field,
      out_field,
      mask_size=None,
      mask_targets=None,
      thickness=1,
      output_dir=None,
      rel_dir=None,
      overwrite=False,
      save_mask_targets=False,
  ):
      """Converts the instance segmentations or polylines in the specified field
      of the collection into semantic segmentation masks.
  
      Args:
          sample_collection: a
              :class:`fiftyone.core.collections.SampleCollection`
          in_field: the name of the objects field for which to render
              segmentation masks. Supported types are
              :class:`fiftyone.core.labels.Detection`,
              :class:`fiftyone.core.labels.Detections`,
              :class:`fiftyone.core.labels.Polyline`, and
              :class:`fiftyone.core.labels.Polylines`
          out_field: the name of the :class:`fiftyone.core.labels.Segmentation`
              field to populate
          mask_size (None): the ``(width, height)`` at which to render the
              segmentation masks. If not provided, masks will be rendered to
              match the resolution of each input image
          mask_targets (None): a dict mapping pixel values (2D masks) or RGB hex
              strings (3D masks) to label strings defining which object classes
              to render and which pixel values to use for each class. If omitted,
              all objects are rendered with pixel value 255
          thickness (1): the thickness, in pixels, at which to render
              (non-filled) polylines
          output_dir (None): an optional output directory in which to write the
              segmentation images. If none is provided, the segmentations are
              stored in the database
          rel_dir (None): an optional relative directory to strip from each input
              filepath to generate a unique identifier that is joined with
              ``output_dir`` to generate an output path for each segmentation
              image. This argument allows for populating nested subdirectories in
              ``output_dir`` that match the shape of the input paths. The path is
              converted to an absolute path (if necessary) via
              :func:`fiftyone.core.storage.normalize_path`
          overwrite (False): whether to delete ``output_dir`` prior to exporting
              if it exists
          save_mask_targets (False): whether to store the ``mask_targets`` on the
              dataset
      """
      fov.validate_collection_label_fields(
          sample_collection,
          in_field,
          (fol.Detection, fol.Detections, fol.Polyline, fol.Polylines),
      )
  
      if mask_size is None:
          sample_collection.compute_metadata()
  
      samples = sample_collection.select_fields(in_field)
      in_field, processing_frames = samples._handle_frame_field(
          in_field
      )
      out_field, _ = samples._handle_frame_field(out_field)
  
      if overwrite and output_dir is not None:
          etau.delete_dir(output_dir)
  
      if output_dir is not None:
          filename_maker = fou.UniqueFilenameMaker(
              output_dir=output_dir, rel_dir=rel_dir, idempotent=False
          )
  
      for sample in samples.iter_samples(autosave=True, progress=True):
          if processing_frames:
              images = sample.frames.values()
          else:
              images = [sample]
  
          if mask_size is not None:
              frame_size = mask_size
          elif processing_frames:
              frame_size = (
                  sample.metadata.frame_width,
                  sample.metadata.frame_height,
              )
          else:
              frame_size = (
                  sample.metadata.width,
                  sample.metadata.height,
              )
  
          for image in images:
              label = image[in_field]
              if label is None:
                  continue
  
              segmentation = None
  
              if isinstance(label, fol.Polyline):
                  label = fol.Polylines(polylines=[label])
  
              if isinstance(label, fol.Detection):
                  label = fol.Detections(detections=[label])
  
              if isinstance(label, fol.Polylines):
                  segmentation = label.to_segmentation(
                      frame_size=frame_size,
                      mask_targets=mask_targets,
                      thickness=thickness,
                  )
  
              if isinstance(label, fol.Detections):
                  segmentation = label.to_segmentation(
                      frame_size=frame_size,
                      mask_targets=mask_targets,
                  )
  
              if output_dir is not None:
                  mask_path = filename_maker.get_output_path(
                      image.filepath, output_ext=".png"
                  )
                  segmentation.export_mask(mask_path, update=True)
  
              image[out_field] = segmentation
  
      if save_mask_targets and mask_targets is not None:
          if not sample_collection.default_mask_targets:
              sample_collection.default_mask_targets = mask_targets
          else:
              sample_collection.mask_targets[out_field] = mask_targets
  
file_path: fiftyone/fiftyone/utils/labels.py
imports: import eta.core.utils
  import fiftyone.core.labels
  import fiftyone.core.utils
  import fiftyone.core.validation
label_desc: Use image node_id 1 for calling a global function with example usage: objects_to_segmentations(sample_collection, in_field, out_field, mask_size, mask_targets, thickness, output_dir, rel_dir, overwrite, save_mask_targets) without return types