code: def _masks_to_polylines(detections, tolerance, error_level):
      polylines = []
      for detection in detections:
          try:
              polyline = detection.to_polyline(tolerance=tolerance)
          except Exception as e:
              polyline = fol.Polyline()
              fou.handle_error(
                  ValueError(
                      "Failed to convert instance mask for object '%s' to "
                      "polygons" % detection.id
                  ),
                  error_level,
                  base_error=e,
              )
  
          polyline.id = detection.id  # keep same ID
          polylines.append(polyline)
  
      return polylines
  
imports: import contextlib
  import itertools
  import logging
  import numpy
  import scipy.spatial
  import eta.core.numutils
  import eta.core.utils
  import fiftyone.core.labels
  import fiftyone.core.utils
  import fiftyone.core.validation
  from .utils3d import compute_cuboid_iou
label_desc: Use image node_id 21 for calling a global function with example usage: _masks_to_polylines(detections, tolerance, error_level) and returns: polylines