docstr: Predict masks for the given input prompts, using the currently set image.
  
  Arguments:
    point_coords (np.ndarray or None): A Nx2 array of point prompts to the
      model. Each point is in (X,Y) in pixels.
    point_labels (np.ndarray or None): A length N array of labels for the
      point prompts. 1 indicates a foreground point and 0 indicates a
      background point.
    box (np.ndarray or None): A length 4 array given a box prompt to the
      model, in XYXY format.
    mask_input (np.ndarray): A low resolution mask input to the model, typically
      coming from a previous prediction iteration. Has form 1xHxW, where
      for SAM, H=W=256.
    multimask_output (bool): If true, the model will return three masks.
      For ambiguous input prompts (such as a single click), this will often
      produce better masks than a single prediction. If only a single
      mask is needed, the model's predicted quality score can be used
      to select the best mask. For non-ambiguous prompts, such as multiple
      input prompts, multimask_output=False can give better results.
    return_logits (bool): If true, returns un-thresholded masks logits
      instead of a binary mask.
  
  Returns:
    (np.ndarray): The output masks in CxHxW format, where C is the
      number of masks, and (H, W) is the original image size.
    (np.ndarray): An array of length C containing the model's
      predictions for the quality of each mask.
    (np.ndarray): An array of shape CxHxW, where C is the number
      of masks and H=W=256. These low resolution logits can be passed to
      a subsequent iteration as mask input.
docstr_tok: ["Predict","masks","for","the","given","input","prompts",",","using","the","currently","set","image",".","Arguments",":","point_coords","(","np.ndarray","or","None",")",":","A","Nx2","array","of","point","prompts","to","the","model",".","Each","point","is","in","(","X",",","Y",")","in","pixels",".","point_labels","(","np.ndarray","or","None",")",":","A","length","N","array","of","labels","for","the","point","prompts",".","1","indicates","a","foreground","point","and","0","indicates","a","background","point",".","box","(","np.ndarray","or","None",")",":","A","length","4","array","given","a","box","prompt","to","the","model",",","in","XYXY","format",".","mask_input","(","np.ndarray",")",":","A","low","resolution","mask","input","to","the","model",",","typically","coming","from","a","previous","prediction","iteration",".","Has","form","1xHxW",",","where","for","SAM",",","H=W=256",".","multimask_output","(","bool",")",":","If","true",",","the","model","will","return","three","masks",".","For","ambiguous","input","prompts","(","such","as","a","single","click",")",",","this","will","often","produce","better","masks","than","a","single","prediction",".","If","only","a","single","mask","is","needed",",","the","model","'s","predicted","quality","score","can","be","used","to","select","the","best","mask",".","For","non-ambiguous","prompts",",","such","as","multiple","input","prompts",",","multimask_output=False","can","give","better","results",".","return_logits","(","bool",")",":","If","true",",","returns","un-thresholded","masks","logits","instead","of","a","binary","mask",".","Returns",":","(","np.ndarray",")",":","The","output","masks","in","CxHxW","format",",","where","C","is","the","number","of","masks",",","and","(","H",",","W",")","is","the","original","image","size",".","(","np.ndarray",")",":","An","array","of","length","C","containing","the","model's","predictions","for","the","quality","of","each","mask",".","(","np.ndarray",")",":","An","array","of","shape","CxHxW",",","where","C","is","the","number","of","masks","and","H=W=256",".","These","low","resolution","logits","can","be","passed","to","a","subsequent","iteration","as","mask","input","."]
code: def predict(
      self,
      point_coords: Optional[np.ndarray] = None,
      point_labels: Optional[np.ndarray] = None,
      box: Optional[np.ndarray] = None,
      mask_input: Optional[np.ndarray] = None,
      multimask_output: bool = True,
      return_logits: bool = False,
  ) -> Tuple[paddle.Tensor, paddle.Tensor, paddle.Tensor]:
      """
      Predict masks for the given input prompts, using the currently set image.
  
      Arguments:
        point_coords (np.ndarray or None): A Nx2 array of point prompts to the
          model. Each point is in (X,Y) in pixels.
        point_labels (np.ndarray or None): A length N array of labels for the
          point prompts. 1 indicates a foreground point and 0 indicates a
          background point.
        box (np.ndarray or None): A length 4 array given a box prompt to the
          model, in XYXY format.
        mask_input (np.ndarray): A low resolution mask input to the model, typically
          coming from a previous prediction iteration. Has form 1xHxW, where
          for SAM, H=W=256.
        multimask_output (bool): If true, the model will return three masks.
          For ambiguous input prompts (such as a single click), this will often
          produce better masks than a single prediction. If only a single
          mask is needed, the model's predicted quality score can be used
          to select the best mask. For non-ambiguous prompts, such as multiple
          input prompts, multimask_output=False can give better results.
        return_logits (bool): If true, returns un-thresholded masks logits
          instead of a binary mask.
  
      Returns:
        (np.ndarray): The output masks in CxHxW format, where C is the
          number of masks, and (H, W) is the original image size.
        (np.ndarray): An array of length C containing the model's
          predictions for the quality of each mask.
        (np.ndarray): An array of shape CxHxW, where C is the number
          of masks and H=W=256. These low resolution logits can be passed to
          a subsequent iteration as mask input.
      """
      if not self.is_image_set:
          raise RuntimeError(
              "An image must be set with .set_image(...) before mask prediction."
          )
  
      # Transform input prompts
      coords_paddle, labels_paddle, box_paddle, mask_input_paddle = (
          None,
          None,
          None,
          None,
      )
      if point_coords is not None:
          assert (
              point_labels is not None
          ), "point_labels must be supplied if point_coords is supplied."
          point_coords = self.transform.apply_coords(
              point_coords, self.original_size
          )
          coords_paddle = paddle.to_tensor(point_coords).cast("float32")
          labels_paddle = paddle.to_tensor(point_labels).cast("int32")
          coords_paddle, labels_paddle = (
              coords_paddle[None, :, :],
              labels_paddle[None, :],
          )
      if box is not None:
          box = self.transform.apply_boxes(box, self.original_size)
          box_paddle = paddle.to_tensor(box).cast("float32")
          box_paddle = box_paddle[None, :]
      if mask_input is not None:
          mask_input_paddle = paddle.to_tensor(mask_input).cast(
              "float32"
          )
          mask_input_paddle = mask_input_paddle[None, :, :, :]
  
      masks, iou_predictions, low_res_masks = self.predict_paddle(
          coords_paddle,
          labels_paddle,
          box_paddle,
          mask_input_paddle,
          multimask_output,
          return_logits=return_logits,
      )
  
      masks = masks[0].detach().cpu().numpy()
      iou_predictions = iou_predictions[0].detach().cpu().numpy()
      low_res_masks = low_res_masks[0].detach().cpu().numpy()
      return masks, iou_predictions, low_res_masks
  
file_path: PaddleSeg/contrib/SegmentAnything/segment_anything/predictor.py
imports: import numpy
  from typing import Optional, Tuple
  import paddle
  from .modeling import Sam
  from .utils.transforms import ResizeLongestSide
label_desc: Use image node_id 4 for calling the SamPredictor obj's underlying member method code with example usage: obj.predict(point_coords, point_labels, box, mask_input, multimask_output, return_logits) and returns: masks,  iou_predictions,  low_res_masks