code: def convert_record_to_fo_sample(
      record,
      field_name: str,
      sample: Union[None, Sample] = None,
      autosave: bool = False,
      transformations=None,  # Undo postprocess via sample: icevision.models.inference.postprocess_bbox
      undo_bbox_tfms_fn: Callable[
          [BBox], BBox
      ] = None,  # Undo postprocess custom fn
      filepath: Union[Path, str] = None,
  ) -> Sample:
      """
      Takes a record and applies it to an 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
      field_name: A fo field name for the sample
      sample: If no sample is given, a sample is created
      autosave: Whether an existing sample should be saved directly
  
      transformations: list of model-pre-processing transforms
  
      undo_bbox_tfms_fn: Custom function, that undoes transformations
  
      filepath: The filepath, if it is not present in the record
  
      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.")
  
      # Validate input
      if transformations is not None and undo_bbox_tfms_fn is not None:
          warn(
              "Both transformations and undo_bbox_tfms_fn is defined. You custom function will be used."
          )
      if transformations is None and undo_bbox_tfms_fn is None:
          warn(
              "No bounding box postprocessing is used. The bboxes might be shifted in fiftyone"
          )
  
      if filepath is not None:
          _internal_filepath = filepath
      else:
          if sample is not None:
              _internal_filepath = sample.filepath
          else:
              _internal_filepath = record.common.filepath
  
      # Prepare undo bbox tfms fn
      img_size = get_img_size(_internal_filepath)
      if undo_bbox_tfms_fn is not None:
          _internal_undo_bbox_tfms = (
              lambda bbox: _convert_bbox_to_fo_bbox(
                  undo_bbox_tfms_fn(bbox),
                  img_size.width,
                  img_size.height,
              )
          )
      elif transformations is not None:
          _internal_undo_bbox_tfms = (
              lambda bbox: _convert_bbox_to_fo_bbox(
                  postprocess_bbox(
                      img_size,
                      bbox,
                      transformations,
                      record.common.width,
                      record.common.height,
                  ),
                  img_size.width,
                  img_size.height,
              )
          )
      else:
          _internal_undo_bbox_tfms = (
              lambda bbox: _convert_bbox_to_fo_bbox(
                  bbox, img_size.width, img_size.height
              )
          )
  
      # Get fo.Detections
      detections = record_to_fo_detections(
          record, _internal_undo_bbox_tfms
      )
  
      # Get sample after successful detection
      if sample is None:
          sample = Sample(_internal_filepath)
      elif isinstance(sample, Sample):
          pass
      else:
          raise ValueError(f"Sample {sample} is not None or fo.Sample")
  
      # Add detections to sample
      sample[field_name] = Detections(detections=detections)
  
      if autosave:
          sample.save()
  
      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 1 for calling a global function with example usage: convert_record_to_fo_sample(record, field_name, sample, autosave, transformations, undo_bbox_tfms_fn, filepath) and returns: sample