code: def test_evaluate_polygons():
      dataset = foz.load_zoo_dataset(
          "coco-2017",
          split="validation",
          label_types=["detections", "segmentations"],
          max_samples=50,
          drop_existing_dataset=True,
      )
  
      # pylint: disable=no-member
      def jitter(labels, delta=None, uniform=True):
          if isinstance(labels, fo.Detections):
              for detection in labels.detections:
                  alpha = random.random()
                  bounding_box = np.array(detection.bounding_box)
  
                  if uniform:
                      bounding_box += (
                          alpha * delta * np.array([1, 1, 0, 0])
                      )
                  else:
                      bounding_box += (
                          alpha * delta * np.random.random(4)
                      )
  
                  detection.bounding_box = bounding_box.tolist()
                  detection.confidence = alpha
  
          if isinstance(labels, fo.Polylines):
              for polyline in labels.polylines:
                  alpha = random.random()
                  points = []
                  for _points in polyline.points:
                      _points = np.array(_points)
  
                      if uniform:
                          _points += (
                              alpha * delta * np.ones(_points.shape)
                          )
                      else:
                          _points += (
                              alpha
                              * delta
                              * np.random.random(_points.shape)
                          )
  
                      points.append(_points.tolist())
  
                  polyline.points = points
                  polyline.confidence = alpha
  
          return labels
  
      # Add polylines
      with fo.ProgressBar() as pb:
          for sample in pb(dataset):
              sample["polylines"] = sample[
                  "segmentations"
              ].to_polylines()
              sample.save()
  
      # doesn't create self-intersecting polygons
      # jit = lambda labels: jitter(labels, delta=0.03, uniform=True)
  
      # likely creates self-intersecting polylines
      jit = lambda labels: jitter(labels, delta=0.05, uniform=False)
  
      # Add predictions
      with fo.ProgressBar() as pb:
          for sample in pb(dataset):
              sample["pred_det"] = jit(sample["detections"].copy())
              sample["pred_seg"] = jit(sample["segmentations"].copy())
              sample["pred_pol"] = jit(sample["polylines"].copy())
              sample.save()
  
      results1 = dataset.evaluate_detections(
          "pred_det",
          gt_field="detections",
          eval_key="det_coco",
          method="coco",
      )
      print(results1.metrics())
  
      results2 = dataset.evaluate_detections(
          "pred_seg",
          gt_field="segmentations",
          eval_key="seg_coco",
          method="coco",
          use_masks=True,
      )
      print(results2.metrics())
  
      results3 = dataset.evaluate_detections(
          "pred_pol",
          gt_field="polylines",
          eval_key="pol_coco",
          method="coco",
      )
      print(results3.metrics())
  
      results4 = dataset.evaluate_detections(
          "pred_pol",
          gt_field="polylines",
          eval_key="pol_coco",
          method="coco",
          use_boxes=True,
      )
      print(results4.metrics())
  
      results1 = dataset.evaluate_detections(
          "pred_det",
          gt_field="detections",
          eval_key="det_oi",
          method="open-images",
      )
      print(results1.metrics())
  
      results2 = dataset.evaluate_detections(
          "pred_seg",
          gt_field="segmentations",
          eval_key="seg_oi",
          method="open-images",
          use_masks=True,
      )
      print(results2.metrics())
  
      results3 = dataset.evaluate_detections(
          "pred_pol",
          gt_field="polylines",
          eval_key="pol_oi",
          method="open-images",
      )
      print(results3.metrics())
  
      results4 = dataset.evaluate_detections(
          "pred_pol",
          gt_field="polylines",
          eval_key="pol_oi",
          method="open-images",
          use_boxes=True,
      )
      print(results4.metrics())
  
file_path: fiftyone/tests/intensive/evaluation_tests.py
imports: import random
  import unittest
  import numpy
  import eta.core.utils
  import pytest
  import fiftyone
  import fiftyone.zoo
  from fiftyone import ViewField
label_desc: Use image node_id 6 for calling a global function with example usage: test_evaluate_polygons() and returns: labels