code: def evaluate_detections(
      samples,
      pred_field,
      gt_field="ground_truth",
      eval_key=None,
      classes=None,
      missing=None,
      method=None,
      iou=0.50,
      use_masks=False,
      use_boxes=False,
      classwise=True,
      dynamic=True,
      **kwargs,
  ):
      """Evaluates the predicted detections in the given samples with respect to
      the specified ground truth detections.
  
      This method supports evaluating the following spatial data types:
  
      -   Object detections in :class:`fiftyone.core.labels.Detections` format
      -   Instance segmentations in :class:`fiftyone.core.labels.Detections`
          format with their ``mask`` attributes populated
      -   Polygons in :class:`fiftyone.core.labels.Polylines` format
      -   Keypoints in :class:`fiftyone.core.labels.Keypoints` format
      -   Temporal detections in :class:`fiftyone.core.labels.TemporalDetections`
          format
  
      For spatial object detection evaluation, this method uses COCO-style
      evaluation by default.
  
      When evaluating keypoints, "IoUs" are computed via
      `object keypoint similarity <https://cocodataset.org/#keypoints-eval>`_.
  
      For temporal segment detection, this method uses ActivityNet-style
      evaluation by default.
  
      You can use the ``method`` parameter to select a different method, and you
      can optionally customize the method by passing additional parameters for
      the method's config class as ``kwargs``.
  
      The natively provided ``method`` values and their associated configs are:
  
      -   ``"coco"``: :class:`fiftyone.utils.eval.coco.COCOEvaluationConfig`
      -   ``"open-images"``: :class:`fiftyone.utils.eval.openimages.OpenImagesEvaluationConfig`
      -   ``"activitynet"``: :class:`fiftyone.utils.eval.activitynet.ActivityNetEvaluationConfig`
  
      If an ``eval_key`` is provided, a number of fields are populated at the
      object- and sample-level recording the results of the evaluation:
  
      -   True positive (TP), false positive (FP), and false negative (FN) counts
          for each sample are saved in top-level fields of each sample::
  
              TP: sample.<eval_key>_tp
              FP: sample.<eval_key>_fp
              FN: sample.<eval_key>_fn
  
          In addition, when evaluating frame-level objects, TP/FP/FN counts are
          recorded for each frame::
  
              TP: frame.<eval_key>_tp
              FP: frame.<eval_key>_fp
              FN: frame.<eval_key>_fn
  
      -   The fields listed below are populated on each individual object; these
          fields tabulate the TP/FP/FN status of the object, the ID of the
          matching object (if any), and the matching IoU::
  
              TP/FP/FN: object.<eval_key>
                    ID: object.<eval_key>_id
                   IoU: object.<eval_key>_iou
  
      Args:
          samples: a :class:`fiftyone.core.collections.SampleCollection`
          pred_field: the name of the field containing the predicted
              :class:`fiftyone.core.labels.Detections`,
              :class:`fiftyone.core.labels.Polylines`,
              :class:`fiftyone.core.labels.Keypoints`,
              or :class:`fiftyone.core.labels.TemporalDetections`
          gt_field ("ground_truth"): the name of the field containing the ground
              truth :class:`fiftyone.core.labels.Detections`,
              :class:`fiftyone.core.labels.Polylines`,
              :class:`fiftyone.core.labels.Keypoints`,
              or :class:`fiftyone.core.labels.TemporalDetections`
          eval_key (None): an evaluation key to use to refer to this evaluation
          classes (None): the list of possible classes. If not provided, the
              observed ground truth/predicted labels are used
          missing (None): a missing label string. Any unmatched objects are given
              this label for results purposes
          method (None): a string specifying the evaluation method to use. The
              supported values are
              ``fo.evaluation_config.detection_backends.keys()`` and the default
              is ``fo.evaluation_config.default_detection_backend``
          iou (0.50): the IoU threshold to use to determine matches
          use_masks (False): whether to compute IoUs using the instances masks in
              the ``mask`` attribute of the provided objects, which must be
              :class:`fiftyone.core.labels.Detection` instances
          use_boxes (False): whether to compute IoUs using the bounding boxes
              of the provided :class:`fiftyone.core.labels.Polyline` instances
              rather than using their actual geometries
          classwise (True): whether to only match objects with the same class
              label (True) or allow matches between classes (False)
          dynamic (True): whether to declare the dynamic object-level attributes
              that are populated on the dataset's schema
          **kwargs: optional keyword arguments for the constructor of the
              :class:`DetectionEvaluationConfig` being used
  
      Returns:
          a :class:`DetectionResults`
      """
      fov.validate_collection_label_fields(
          samples,
          (pred_field, gt_field),
          (
              fol.Detections,
              fol.Polylines,
              fol.Keypoints,
              fol.TemporalDetections,
          ),
          same_type=True,
      )
  
      label_type = samples._get_label_field_type(gt_field)
      is_temporal = issubclass(label_type, fol.TemporalDetections)
  
      if is_temporal:
          fov.validate_video_collection(samples)
      else:
          kwargs.update(dict(use_masks=use_masks, use_boxes=use_boxes))
  
      config = _parse_config(
          pred_field,
          gt_field,
          method,
          is_temporal,
          iou=iou,
          classwise=classwise,
          **kwargs,
      )
  
      eval_method = config.build()
      eval_method.ensure_requirements()
  
      eval_method.register_run(samples, eval_key)
      eval_method.register_samples(samples, eval_key, dynamic=dynamic)
  
      processing_frames = samples._is_frame_field(pred_field)
  
      if eval_key is not None:
          tp_field = "%s_tp" % eval_key
          fp_field = "%s_fp" % eval_key
          fn_field = "%s_fn" % eval_key
  
      if config.requires_additional_fields:
          _samples = samples
      else:
          _samples = samples.select_fields([gt_field, pred_field])
  
      matches = []
      logger.info("Evaluating detections...")
      for sample in _samples.iter_samples(progress=True):
          if processing_frames:
              docs = sample.frames.values()
          else:
              docs = [sample]
  
          sample_tp = 0
          sample_fp = 0
          sample_fn = 0
          for doc in docs:
              doc_matches = eval_method.evaluate(doc, eval_key=eval_key)
              matches.extend(doc_matches)
              tp, fp, fn = _tally_matches(doc_matches)
              sample_tp += tp
              sample_fp += fp
              sample_fn += fn
  
              if processing_frames and eval_key is not None:
                  doc[tp_field] = tp
                  doc[fp_field] = fp
                  doc[fn_field] = fn
  
          if eval_key is not None:
              sample[tp_field] = sample_tp
              sample[fp_field] = sample_fp
              sample[fn_field] = sample_fn
              sample.save()
  
      results = eval_method.generate_results(
          samples,
          matches,
          eval_key=eval_key,
          classes=classes,
          missing=missing,
      )
      eval_method.save_run_results(samples, eval_key, results)
  
      return results
  
imports: from copy import deepcopy
  import inspect
  import itertools
  import logging
  import numpy
  import eta.core.utils
  import fiftyone
  import fiftyone.core.evaluation
  import fiftyone.core.fields
  import fiftyone.core.labels
  import fiftyone.core.utils
  import fiftyone.core.validation
  from .base import BaseEvaluationResults
label_desc: Use image node_id 1 for calling a global function with example usage: evaluate_detections(samples, pred_field, gt_field, eval_key, classes, missing, method, iou, use_masks, use_boxes, classwise, dynamic) and returns: results