code: def _to_detections(result, confidence_thresh=None):
      if result.boxes is None:
          return None
  
      classes = np.rint(result.boxes.cls.detach().cpu().numpy()).astype(
          int
      )
      boxes = result.boxes.xywhn.detach().cpu().numpy().astype(float)
      confs = result.boxes.conf.detach().cpu().numpy().astype(float)
  
      detections = []
      for cls, box, conf in zip(classes, boxes, confs):
          if confidence_thresh is not None and conf < confidence_thresh:
              continue
  
          label = result.names[cls]
          xc, yc, w, h = box
  
          detection = fol.Detection(
              label=label,
              bounding_box=[xc - 0.5 * w, yc - 0.5 * h, w, h],
              confidence=conf,
          )
          detections.append(detection)
  
      return fol.Detections(detections=detections)
  
imports: import itertools
  import numpy
  from PIL import Image
  from fiftyone.core.config import Config
  import fiftyone.core.labels
  from fiftyone.core.models import Model
  import fiftyone.utils.torch
  import fiftyone.core.utils
label_desc: Use image node_id 3 for calling a global function with example usage: _to_detections(result, confidence_thresh) and returns: fol, None