class_docstr: This class stores the segmentation masks for all objects in one image, in
  the form of bitmaps.
  
  Attributes:
      tensor: bool Tensor of N,H,W, representing N instances in the image.
class_docstr_tok: ["This","class","stores","the","segmentation","masks","for","all","objects","in","one","image",",","in","the","form","of","bitmaps",".","Attributes",":","tensor",":","bool","Tensor","of","N",",","H",",","W",",","representing","N","instances","in","the","image","."]
docstr: Crop each bitmask by the given box, and resize results to (mask_size, mask_size).
  This can be used to prepare training targets for Mask R-CNN.
  It has less reconstruction error compared to rasterization with polygons.
  However we observe no difference in accuracy,
  but BitMasks requires more memory to store all the masks.
  
  Args:
      boxes (Tensor): Nx4 tensor storing the boxes for each mask
      mask_size (int): the size of the rasterized mask.
  
  Returns:
      Tensor:
          A bool tensor of shape (N, mask_size, mask_size), where
          N is the number of predicted boxes for this image.
docstr_tok: ["Crop","each","bitmask","by","the","given","box",",","and","resize","results","to","(","mask_size",",","mask_size",")",".","This","can","be","used","to","prepare","training","targets","for","Mask","R-CNN",".","It","has","less","reconstruction","error","compared","to","rasterization","with","polygons",".","However","we","observe","no","difference","in","accuracy",",","but","BitMasks","requires","more","memory","to","store","all","the","masks",".","Args",":","boxes","(","Tensor",")",":","Nx4","tensor","storing","the","boxes","for","each","mask","mask_size","(","int",")",":","the","size","of","the","rasterized","mask",".","Returns",":","Tensor",":","A","bool","tensor","of","shape","(","N",",","mask_size",",","mask_size",")",",","where","N","is","the","number","of","predicted","boxes","for","this","image","."]
code: def crop_and_resize(
      self, boxes: torch.Tensor, mask_size: int
  ) -> torch.Tensor:
      """
      Crop each bitmask by the given box, and resize results to (mask_size, mask_size).
      This can be used to prepare training targets for Mask R-CNN.
      It has less reconstruction error compared to rasterization with polygons.
      However we observe no difference in accuracy,
      but BitMasks requires more memory to store all the masks.
  
      Args:
          boxes (Tensor): Nx4 tensor storing the boxes for each mask
          mask_size (int): the size of the rasterized mask.
  
      Returns:
          Tensor:
              A bool tensor of shape (N, mask_size, mask_size), where
              N is the number of predicted boxes for this image.
      """
      assert len(boxes) == len(self), "{} != {}".format(
          len(boxes), len(self)
      )
      device = self.tensor.device
  
      batch_inds = torch.arange(len(boxes), device=device).to(
          dtype=boxes.dtype
      )[:, None]
      rois = torch.cat([batch_inds, boxes], dim=1)  # Nx5
  
      bit_masks = self.tensor.to(dtype=torch.float32)
      rois = rois.to(device=device)
      output = (
          torchvision.ops.ROIAlign(
              (mask_size, mask_size), 1.0, 0, aligned=True
          )
          .forward(bit_masks[:, None, :, :], rois)
          .squeeze(1)
      )
      output = output >= 0.5
      return output
  
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 10 for calling the BitMasks obj's underlying member method code with example usage: obj.crop_and_resize(boxes, mask_size) and returns: output