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: Support indexing over the instances and return a `PolygonMasks` object.
  `item` can be:
  
  1. An integer. It will return an object with only one instance.
  2. A slice. It will return an object with the selected instances.
  3. A list[int]. It will return an object with the selected instances,
     correpsonding to the indices in the list.
  4. A vector mask of type BoolTensor, whose length is num_instances.
     It will return an object with the instances whose mask is nonzero.
docstr_tok: ["Support","indexing","over","the","instances","and","return","a","`","PolygonMasks","`","object",".","`","item","`","can","be",":","1",".","An","integer",".","It","will","return","an","object","with","only","one","instance",".","2",".","A","slice",".","It","will","return","an","object","with","the","selected","instances",".","3",".","A","list","[","int","]",".","It","will","return","an","object","with","the","selected","instances",",","correpsonding","to","the","indices","in","the","list",".","4",".","A","vector","mask","of","type","BoolTensor",",","whose","length","is","num_instances",".","It","will","return","an","object","with","the","instances","whose","mask","is","nonzero","."]
code: def __getitem__(
      self, item: Union[int, slice, List[int], torch.BoolTensor]
  ) -> "PolygonMasks":
      """
      Support indexing over the instances and return a `PolygonMasks` object.
      `item` can be:
  
      1. An integer. It will return an object with only one instance.
      2. A slice. It will return an object with the selected instances.
      3. A list[int]. It will return an object with the selected instances,
         correpsonding to the indices in the list.
      4. A vector mask of type BoolTensor, whose length is num_instances.
         It will return an object with the instances whose mask is nonzero.
      """
      if isinstance(item, int):
          selected_polygons = [self.polygons[item]]
      elif isinstance(item, slice):
          selected_polygons = self.polygons[item]
      elif isinstance(item, list):
          selected_polygons = [self.polygons[i] for i in item]
      elif isinstance(item, torch.Tensor):
          # Polygons is a list, so we have to move the indices back to CPU.
          if item.dtype == torch.bool:
              assert item.dim() == 1, item.shape
              item = item.nonzero().squeeze(1).cpu().numpy().tolist()
          elif item.dtype in [torch.int32, torch.int64]:
              item = item.cpu().numpy().tolist()
          else:
              raise ValueError(
                  "Unsupported tensor dtype={} for indexing!".format(
                      item.dtype
                  )
              )
          selected_polygons = [self.polygons[i] for i in item]
      return PolygonMasks(selected_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 6 for calling the PolygonMasks obj's underlying member method code with example usage: obj.__getitem__(item) and returns: PolygonMasks