code: def _process_batch(
      self,
      points: np.ndarray,
      im_size: Tuple[int, ...],
      crop_box: List[int],
      orig_size: Tuple[int, ...],
  ) -> MaskData:
      orig_h, orig_w = orig_size
  
      # Run model on this batch
      transformed_points = self.predictor.transform.apply_coords(
          points, im_size
      )
      in_points = paddle.to_tensor(transformed_points)
      in_labels = paddle.ones(
          shape=[
              in_points.shape[0],
          ],
          dtype="int64",
      )
      masks, iou_preds, _ = self.predictor.predict_paddle(
          in_points[:, None, :],
          in_labels[:, None],
          multimask_output=True,
          return_logits=True,
      )
  
      # Serialize predictions and store in MaskData
      data = MaskData(
          masks=masks.flatten(0, 1),
          iou_preds=iou_preds.flatten(0, 1),
          points=paddle.to_tensor(
              points.repeat(masks.shape[1], axis=0)
          ),
      )
      del masks
  
      # Filter by predicted IoU
      if self.pred_iou_thresh > 0.0:
          keep_mask = data["iou_preds"] > self.pred_iou_thresh
          data.filter(keep_mask)
  
      # Calculate stability score
      data["stability_score"] = calculate_stability_score(
          data["masks"],
          self.predictor.model.mask_threshold,
          self.stability_score_offset,
      )
  
      if self.stability_score_thresh > 0.0:
          keep_mask = (
              data["stability_score"] >= self.stability_score_thresh
          )
          data.filter(keep_mask)
  
      # Threshold masks and calculate boxes
      data["masks"] = (
          data["masks"] > self.predictor.model.mask_threshold
      ).cast(paddle.float32)
      data["boxes"] = batched_mask_to_box(data["masks"])
  
      # Filter boxes that touch crop boundaries
      keep_mask = ~is_box_near_crop_edge(
          data["boxes"], crop_box, [0, 0, orig_w, orig_h]
      )
      if not paddle.all(keep_mask):
          data.filter(keep_mask)
  
      # Compress to RLE
      data["masks"] = uncrop_masks(
          data["masks"], crop_box, orig_h, orig_w
      )
      data["rles"] = mask_to_rle_paddle(
          data["masks"].cast(paddle.float32)
      )
      del data["masks"]
  
      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 5 for calling the SamAutomaticMaskGenerator obj's underlying member method code with example usage: obj._process_batch(points, im_size, crop_box, orig_size) and returns: data