code: def _generate_masks(self, image: np.ndarray) -> MaskData:
      def box_area(boxes):
          """
          Computes the area of a set of bounding boxes, which are specified by their
          (x1, y1, x2, y2) coordinates.
  
          Args:
              boxes (Tensor[N, 4]): boxes for which the area will be computed. They
                  are expected to be in (x1, y1, x2, y2) format with
                  ``0 <= x1 < x2`` and ``0 <= y1 < y2``.
  
          Returns:
              Tensor[N]: the area for each box
          """
          if "float" in boxes.dtype:
              boxes = boxes.cast("float64")
          elif "int" in boxes.dtype:
              boxes = boxes.cast("int64")
  
          boxes = boxes
          return (boxes[:, 2] - boxes[:, 0]) * (
              boxes[:, 3] - boxes[:, 1]
          )
  
      orig_size = image.shape[:2]
      crop_boxes, layer_idxs = generate_crop_boxes(
          orig_size, self.crop_n_layers, self.crop_overlap_ratio
      )
  
      # Iterate over image crops
      data = MaskData()
      for crop_box, layer_idx in zip(crop_boxes, layer_idxs):
          crop_data = self._process_crop(
              image, crop_box, layer_idx, orig_size
          )
          data.cat(crop_data)
  
      # Remove duplicate masks between crops
      if len(crop_boxes) > 1:
          # Prefer masks from smaller crops
          scores = 1 / box_area(data["crop_boxes"])
          scores = scores.to(data["boxes"].device)
          keep_by_nms = nms(
              data["boxes"].cast("float32"),
              scores=scores,
              category_idxs=paddle.zeros(
                  len(data["boxes"])
              ),  # categories
              iou_threshold=self.crop_nms_thresh,
          )
          data.filter(keep_by_nms)
  
      data.to_numpy()
      return data
  
file_path: PaddleSeg/contrib/SegmentAnything/segment_anything/automatic_mask_generator.py
imports: import numpy
  import paddle
  from paddle.vision.ops import nms
  from typing import Any, Dict, List, Optional, Tuple
  from .modeling import Sam
  from .predictor import SamPredictor
  from .utils.amg import MaskData, area_from_rle, batch_iterator, batched_mask_to_box, box_xyxy_to_xywh, build_all_layer_point_grids, calculate_stability_score, coco_encode_rle, generate_crop_boxes, is_box_near_crop_edge, mask_to_rle_paddle, remove_small_regions, rle_to_mask, uncrop_boxes_xyxy, uncrop_masks, uncrop_points
label_desc: Use image node_id 3 for calling the SamAutomaticMaskGenerator obj's underlying member method code with example usage: obj._generate_masks(image) and returns: data, unknown