class_docstr: Wrapper for running `Segment Anything <https://segment-anything.com>`_
  inference.
  
  Box prompt example::
  
      import fiftyone as fo
      import fiftyone.zoo as foz
  
      dataset = foz.load_zoo_dataset(
          "quickstart", max_samples=25, shuffle=True, seed=51
      )
  
      model = foz.load_zoo_model("segment-anything-vitb-torch")
  
      # Prompt with boxes
      dataset.apply_model(
          model,
          label_field="segmentations",
          prompt_field="ground_truth",
      )
  
      session = fo.launch_app(dataset)
  
  Keypoint prompt example::
  
      import fiftyone as fo
      import fiftyone.zoo as foz
  
      dataset = foz.load_zoo_dataset(
          "coco-2017",
          split="validation",
          label_types="detections",
          classes=["person"],
          max_samples=25,
          only_matching=True,
      )
  
      # Generate some keypoints
      model = foz.load_zoo_model("keypoint-rcnn-resnet50-fpn-coco-torch")
      dataset.default_skeleton = model.skeleton
      dataset.apply_model(model, label_field="gt")
  
      model = foz.load_zoo_model("segment-anything-vitb-torch")
  
      # Prompt with keypoints
      dataset.apply_model(
          model,
          label_field="segmentations",
          prompt_field="gt_keypoints",
      )
  
      session = fo.launch_app(dataset)
  
  Automatic segmentation example::
  
      import fiftyone as fo
      import fiftyone.zoo as foz
  
      dataset = foz.load_zoo_dataset(
          "quickstart", max_samples=5, shuffle=True, seed=51
      )
  
      model = foz.load_zoo_model("segment-anything-vitb-torch")
  
      # Automatic segmentation
      dataset.apply_model(model, label_field="auto")
  
      session = fo.launch_app(dataset)
  
  Args:
      config: a :class:`SegmentAnythingModelConfig`
class_docstr_tok: ["Wrapper","for","running","`","Segment","Anything","<","https",":","\/\/segment-anything.com",">","`","_","inference",".","Box","prompt","example",":",":","import","fiftyone","as","fo","import","fiftyone.zoo","as","foz","dataset","=","foz.load_zoo_dataset","(","``","quickstart","''",",","max_samples=25",",","shuffle=True",",","seed=51",")","model","=","foz.load_zoo_model","(","``","segment-anything-vitb-torch","''",")","#","Prompt","with","boxes","dataset.apply_model","(","model",",","label_field=","''","segmentations","''",",","prompt_field=","''","ground_truth","''",",",")","session","=","fo.launch_app","(","dataset",")","Keypoint","prompt","example",":",":","import","fiftyone","as","fo","import","fiftyone.zoo","as","foz","dataset","=","foz.load_zoo_dataset","(","``","coco-2017","''",",","split=","''","validation","''",",","label_types=","''","detections","''",",","classes=","[","``","person","''","]",",","max_samples=25",",","only_matching=True",",",")","#","Generate","some","keypoints","model","=","foz.load_zoo_model","(","``","keypoint-rcnn-resnet50-fpn-coco-torch","''",")","dataset.default_skeleton","=","model.skeleton","dataset.apply_model","(","model",",","label_field=","''","gt","''",")","model","=","foz.load_zoo_model","(","``","segment-anything-vitb-torch","''",")","#","Prompt","with","keypoints","dataset.apply_model","(","model",",","label_field=","''","segmentations","''",",","prompt_field=","''","gt_keypoints","''",",",")","session","=","fo.launch_app","(","dataset",")","Automatic","segmentation","example",":",":","import","fiftyone","as","fo","import","fiftyone.zoo","as","foz","dataset","=","foz.load_zoo_dataset","(","``","quickstart","''",",","max_samples=5",",","shuffle=True",",","seed=51",")","model","=","foz.load_zoo_model","(","``","segment-anything-vitb-torch","''",")","#","Automatic","segmentation","dataset.apply_model","(","model",",","label_field=","''","auto","''",")","session","=","fo.launch_app","(","dataset",")","Args",":","config",":","a",":","class",":","`","SegmentAnythingModelConfig","`"]
code: def _forward_pass_points(self, imgs):
      sam_predictor = sam.SamPredictor(self._model)
      self._output_processor = fout.InstanceSegmenterOutputProcessor(
          self._curr_classes
      )
  
      outputs = []
      for img, keypoints in zip(imgs, self._curr_prompts):
          inp = _to_sam_input(img)
          sam_predictor.set_image(inp)
          h, w = img.size(1), img.size(2)
  
          boxes, labels, scores, masks = [], [], [], []
  
          ## If no keypoints, return empty tensors instead of running SAM
          if keypoints is None or len(keypoints.keypoints) == 0:
              outputs.append(
                  {
                      "boxes": torch.tensor([[]]),
                      "labels": torch.empty([0, 4]),
                      "masks": torch.empty([0, 1, h, w]),
                  }
              )
              continue
  
          for kp in keypoints.keypoints:
              sam_points, sam_labels = _to_sam_points(kp.points, w, h)
  
              multi_mask, mask_scores, _ = sam_predictor.predict(
                  point_coords=sam_points,
                  point_labels=sam_labels,
                  multimask_output=True,
              )
  
              mask_index = self.config.points_mask_index
              if mask_index is None:
                  mask_index = np.argmax(mask_scores)
  
              mask = multi_mask[mask_index].astype(int)
              if mask.any():
                  boxes.append(_mask_to_box(mask))
                  labels.append(self._curr_classes.index(kp.label))
                  scores.append(min(1.0, np.max(mask_scores)))
                  masks.append(mask)
  
          outputs.append(
              {
                  "boxes": torch.tensor(
                      boxes, device=sam_predictor.device
                  ),
                  "labels": torch.tensor(
                      labels, device=sam_predictor.device
                  ),
                  "scores": torch.tensor(
                      scores, device=sam_predictor.device
                  ),
                  "masks": torch.tensor(
                      np.array(masks), device=sam_predictor.device
                  ).unsqueeze(1),
              }
          )
  
      return outputs
  
imports: import numpy
  import eta.core.utils
  import fiftyone.core.labels
  import fiftyone.core.utils
  import fiftyone.utils.torch
  import fiftyone.zoo.models
  import torch
label_desc: Use image node_id 12 for calling the SegmentAnythingModel obj's underlying member method code with example usage: obj._forward_pass_points(imgs) and returns: outputs