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).
      """
      assert isinstance(polygons, list), (
          "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]:
          assert isinstance(polygons_per_instance, list), (
              "Cannot create polygons: Expect a list of polygons per instance. "
              "Got '{}' instead.".format(type(polygons_per_instance))
          )
          # transform the polygon to a tensor
          polygons_per_instance = [
              _make_array(p) for p in polygons_per_instance
          ]
          for polygon in polygons_per_instance:
              assert len(polygon) % 2 == 0 and len(polygon) >= 6
          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
  from typing import Any, Iterator, List, Union
  import numpy
  import torch
  import torchvision
  from .boxes import Boxes
label_desc: Use image node_id 1 to create a new PolygonMasks object  with example: obj = PolygonMasks(polygons)