code: def convert_prediction_to_fo_sample(
      prediction: Prediction,
      gt_field_name="ground_truth",
      pred_field_name="prediction",
      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
  ) -> Sample:
      """
      Takes a prediction object and created a fiftyone sample.
  
      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
      ----------
      record: An icevision record
      gt_field_name: Name of the ground truth field in the sample
      pred_field_name: Name of the prediction field in the sample
  
      transformations: list of model-pre-processing transforms
  
      undo_bbox_tfms_fn: Custom function, that undoes transformations
  
      Returns
      -------
      fo.Sample, which can be directly added to a given Fiftyone dataset
      """
  
      if not fiftyone_available:
          raise ImportError("Fiftyone is not installed on you system.")
  
      # Create fo sample
      sample = Sample(prediction.ground_truth.common.filepath)
  
      # Add gt
      convert_record_to_fo_sample(
          prediction.ground_truth,
          gt_field_name,
          sample,
          False,
          transformations,
          undo_bbox_tfms_fn,
      )
  
      # Add prediction
      convert_record_to_fo_sample(
          prediction.pred,
          pred_field_name,
          sample,
          False,
          transformations,
          undo_bbox_tfms_fn,
          filepath=prediction.ground_truth.common.filepath,
      )
  
      return sample
  
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 3 for calling a global function with example usage: convert_prediction_to_fo_sample(prediction, gt_field_name, pred_field_name, transformations, undo_bbox_tfms_fn) and returns: sample