code: def segmentations_to_detections(
      sample_collection,
      in_field,
      out_field,
      mask_targets=None,
      mask_types="stuff",
  ):
      """Converts the semantic segmentations masks in the specified field of the
      collection into :class:`fiftyone.core.labels.Detections` with instance
      masks populated.
  
      Each ``"stuff"`` class will be converted to a single
      :class:`fiftyone.core.labels.Detection` whose instance mask spans all
      region(s) of the class.
  
      Each ``"thing"`` class will result in one
      :class:`fiftyone.core.labels.Detection` instance per connected region of
      that class in the segmentation.
  
      Args:
          sample_collection: a
              :class:`fiftyone.core.collections.SampleCollection`
          in_field: the name of the :class:`fiftyone.core.labels.Segmentation`
              field to convert
          out_field: the name of the
              :class:`fiftyone.core.labels.Detections` field to populate
          mask_targets (None): a dict mapping pixel values (2D masks) or RGB hex
              strings (3D masks) to label strings defining which object classes
              to label and which pixel values to use for each class. If omitted,
              all labels are assigned to the pixel values
          mask_types ("stuff"): whether the classes are ``"stuff"`` (amorphous
              regions of pixels) or ``"thing"`` (connected regions, each
              representing an instance of the thing). Can be any of the
              following:
  
              -   ``"stuff"`` if all classes are stuff classes
              -   ``"thing"`` if all classes are thing classes
              -   a dict mapping pixel values (2D masks) or RGB hex strings (3D
                  masks) to ``"stuff"`` or ``"thing"`` for each class
      """
      fov.validate_collection_label_fields(
          sample_collection,
          in_field,
          fol.Segmentation,
      )
  
      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)
  
      for sample in samples.iter_samples(autosave=True, progress=True):
          if processing_frames:
              images = sample.frames.values()
          else:
              images = [sample]
  
          for image in images:
              label = image[in_field]
              if label is None:
                  continue
  
              image[out_field] = label.to_detections(
                  mask_targets=mask_targets, mask_types=mask_types
              )
  
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 6 for calling a global function with example usage: segmentations_to_detections(sample_collection, in_field, out_field, mask_targets, mask_types) without return types