code: def create_fo_dataset(
      detections: List[Any],
      dataset_name: str,
      exist_ok: bool = False,
      persistent=False,
      field_name: str = "icevision_record",
      transformations=None,  # Undo postprocess via sample: icevision.models.inference.postprocess_bbox
      undo_bbox_tfms_fn: Callable[
          [Union[List[int], BBox]], List[int]
      ] = None,  # Undo postprocess custom fn
  ) -> Dataset:
      """
      Takes an iter of either Predictions or records and created or adds them to a fo.Dataset
  
      A record contains a preprocessed image of you data. However, fiftyone expects an filepath to you image. Thus, we need to undo the pre-processing
      of the bounding box. Therefore, we have provide 2 methods
  
          - The postprocess_bbox() function form icevision.models.inference
  
          - A custom undo_bbox_tfms_fn
  
      If sample is not defined, a new sample is created.
  
      Parameters
      ----------
      detections: An iterable of iv Predictions or records
      dataset_name: Name of dataset
      exist_ok: Whether the data should be added to an existing dataset (active Opt-in)
      persistent:  Whether a dataset should be persistent on creation
      field_name: The field name that is provided if records are in the iterable
  
      transformations: list of model-pre-processing transforms
      undo_bbox_tfms_fn: Custom function, that undoes transformations
  
      Returns
      -------
      fo.Dataset
      """
  
      if not fiftyone_available:
          raise ImportError("Fiftyone is not installed on you system.")
  
      # Validate input
      if dataset_name in list_datasets():
          if exist_ok:
              _internal_dataset = load_dataset(dataset_name)
          else:
              raise ValueError(
                  f"Dataset with name {dataset_name} already exist and exist_ok is {exist_ok}"
              )
      else:
          _internal_dataset = Dataset(
              name=dataset_name, persistent=persistent
          )
  
      _sample_list = []
      for element in detections:
          if isinstance(element, Prediction):
              _sample_list.append(
                  convert_prediction_to_fo_sample(
                      element,
                      transformations=transformations,
                      undo_bbox_tfms_fn=undo_bbox_tfms_fn,
                  )
              )
          else:
              _sample_list.append(
                  convert_record_to_fo_sample(
                      element,
                      field_name=field_name,
                      transformations=transformations,
                      undo_bbox_tfms_fn=undo_bbox_tfms_fn,
                  )
              )
  
      _internal_dataset.add_samples(_sample_list)
  
      return _internal_dataset
  
file_path: icevision/icevision/data/convert_records_to_fo.py
imports: from PIL import Image
  from warnings import warn
  from pathlib import Path
  from icevision import tfms
  from icevision.core.bbox import BBox
  from icevision.data.prediction import Prediction
  from icevision.models.inference import postprocess_bbox
  from icevision.soft_dependencies import SoftDependencies
  from icevision.utils.imageio import get_img_size
  from typing import Any, Callable, Union, Iterable, List, Tuple
label_desc: Use image node_id 4 for calling a global function with example usage: create_fo_dataset(detections, dataset_name, exist_ok, persistent, field_name, transformations, undo_bbox_tfms_fn) and returns: _internal_dataset