class_docstr: A :class:`.Output` which converts model outputs to FiftyOne detection format.
  
  Args:
      labels: A list of labels, assumed to map the class index to the label for that class.
      threshold: a score threshold to apply to candidate detections.
      return_filepath: Boolean determining whether to return a dict
          containing filepath and FiftyOne labels (True) or only a
          list of FiftyOne labels (False)
class_docstr_tok: ["A",":","class",":","`",".Output","`","which","converts","model","outputs","to","FiftyOne","detection","format",".","Args",":","labels",":","A","list","of","labels",",","assumed","to","map","the","class","index","to","the","label","for","that","class",".","threshold",":","a","score","threshold","to","apply","to","candidate","detections",".","return_filepath",":","Boolean","determining","whether","to","return","a","dict","containing","filepath","and","FiftyOne","labels","(","True",")","or","only","a","list","of","FiftyOne","labels","(","False",")"]
code: def transform(
      self, sample: Dict[str, Any]
  ) -> Union[Detections, Dict[str, Any]]:
      if DataKeys.METADATA not in sample:
          raise ValueError(
              "sample requires DataKeys.METADATA to use a FiftyOneDetectionLabelsOutput output."
          )
  
      height, width = sample[DataKeys.METADATA]["output_size"]
  
      detections = []
  
      preds = sample[DataKeys.PREDS]
  
      for bbox, label, score in zip(
          preds["bboxes"], preds["labels"], preds["scores"]
      ):
          confidence = score.tolist()
  
          if self.threshold is not None and confidence < self.threshold:
              continue
  
          xmin, ymin, box_width, box_height = (
              bbox["xmin"],
              bbox["ymin"],
              bbox["width"],
              bbox["height"],
          )
          box = [
              (xmin / width).item(),
              (ymin / height).item(),
              (box_width / width).item(),
              (box_height / height).item(),
          ]
  
          label = label.item()
          label = (
              self._labels[label]
              if self._labels is not None
              else str(int(label))
          )
  
          detections.append(
              fo.Detection(
                  label=label,
                  bounding_box=box,
                  confidence=confidence,
              )
          )
      fo_predictions = fo.Detections(detections=detections)
      if self.return_filepath:
          filepath = sample[DataKeys.METADATA]["filepath"]
          return {"filepath": filepath, "predictions": fo_predictions}
      return fo_predictions
  
file_path: lightning-flash/src/flash/image/detection/output.py
imports: from typing import Any, Dict, List, Optional, Union
  from flash.core.data.io.input import DataKeys
  from flash.core.data.io.output import Output
  from flash.core.model import Task
  from flash.core.registry import FlashRegistry
  from flash.core.utilities.imports import _FIFTYONE_AVAILABLE, lazy_import, requires
  from flash.core.utilities.providers import _FIFTYONE
label_desc: Use image node_id 3 for calling the FiftyOneDetectionLabelsOutput obj's underlying member method code with example usage: obj.transform(sample) and returns: fo_predictions, dict