class_docstr: This class stores the segmentation masks for all objects in one image, in the form of polygons.
  
  Attributes:
      polygons: list[list[ndarray]]. Each ndarray is a float64 vector representing a polygon.
class_docstr_tok: ["This","class","stores","the","segmentation","masks","for","all","objects","in","one","image",",","in","the","form","of","polygons",".","Attributes",":","polygons",":","list","[","list","[","ndarray","]","]",".","Each","ndarray","is","a","float64","vector","representing","a","polygon","."]
docstr: Arguments:
      polygons (list[list[np.ndarray]]): The first
          level of the list correspond to individual instances,
          the second level to all the polygons that compose the
          instance, and the third level to the polygon coordinates.
          The third level array should have the format of
          [x0, y0, x1, y1, ..., xn, yn] (n >= 3).
docstr_tok: ["Arguments",":","polygons","(","list","[","list","[","np.ndarray","]","]",")",":","The","first","level","of","the","list","correspond","to","individual","instances",",","the","second","level","to","all","the","polygons","that","compose","the","instance",",","and","the","third","level","to","the","polygon","coordinates",".","The","third","level","array","should","have","the","format","of","[","x0",",","y0",",","x1",",","y1",",","...",",","xn",",","yn","]","(","n",">","=","3",")","."]
code: def __init__(
      self, polygons: List[List[Union[torch.Tensor, np.ndarray]]]
  ):
      """
      Arguments:
          polygons (list[list[np.ndarray]]): The first
              level of the list correspond to individual instances,
              the second level to all the polygons that compose the
              instance, and the third level to the polygon coordinates.
              The third level array should have the format of
              [x0, y0, x1, y1, ..., xn, yn] (n >= 3).
      """
      if not isinstance(polygons, list):
          raise ValueError(
              "Cannot create PolygonMasks: Expect a list of list of polygons per image. "
              "Got '{}' instead.".format(type(polygons))
          )
  
      def _make_array(t: Union[torch.Tensor, np.ndarray]) -> np.ndarray:
          # Use float64 for higher precision, because why not?
          # Always put polygons on CPU (self.to is a no-op) since they
          # are supposed to be small tensors.
          # May need to change this assumption if GPU placement becomes useful
          if isinstance(t, torch.Tensor):
              t = t.cpu().numpy()
          return np.asarray(t).astype("float64")
  
      def process_polygons(
          polygons_per_instance: List[Union[torch.Tensor, np.ndarray]]
      ) -> List[np.ndarray]:
          if not isinstance(polygons_per_instance, list):
              raise ValueError(
                  "Cannot create polygons: Expect a list of polygons per instance. "
                  "Got '{}' instead.".format(
                      type(polygons_per_instance)
                  )
              )
          # transform each polygon to a numpy array
          polygons_per_instance = [
              _make_array(p) for p in polygons_per_instance
          ]
          for polygon in polygons_per_instance:
              if len(polygon) % 2 != 0 or len(polygon) < 6:
                  raise ValueError(
                      f"Cannot create a polygon from {len(polygon)} coordinates."
                  )
          return polygons_per_instance
  
      self.polygons: List[List[np.ndarray]] = [
          process_polygons(polygons_per_instance)
          for polygons_per_instance in polygons
      ]
  
imports: import copy
  import itertools
  import numpy
  from typing import Any, Iterator, List, Union
  import pycocotools.mask
  import torch
  from torch import device
  from detectron2.layers.roi_align import ROIAlign
  from detectron2.utils.memory import retry_if_cuda_oom
  from .boxes import Boxes
label_desc: Use image node_id 1 to create a new PolygonMasks object  with example: obj = PolygonMasks(polygons)