facebookresearch / facebookresearch/segment-anything
How can multiple points and deletions be done simultaneously?
- Dominant language
- Jupyter Notebook
- Stars
- 54.9k
- Forks
- 6.4k
- PR merge metrics
- No merged PRs in 30d
Description

How should I implement multiple points as shown above? And what about deleting points? I tried this and it couldn't capture the effect in the demo
The following is the code. May I ask how to achieve the same effect as the demo
sam_checkpoint = "../sam_vit_h_4b8939.pth"
model_type = "default"
device = "cpu"
sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
sam.to(device=device)
predictor = SamPredictor(sam)
predictor.set_image(image)
input_point = np.array([[900, 450]])
input_label = np.array([1])
# mask_input = np.array([500, 900])
masks, scores, logits = predictor.predict(
point_coords=input_point,
point_labels=input_label,
multimask_output=False,
)
plt.figure(figsize=(10, 10))
show_mask(masks[0], plt.gca())
plt.show()
input_point = np.array([[500, 37], [500, 800], [1600, 650]])
input_label = np.array([1, 1, 1])
mask_input = logits[np.argmax(scores), :, :]
print("mask_input", mask_input)
# 使用SamPredictor.prpredict进行预测。该模型返回掩码、这些掩码的质量预测以及可以传递到下一次预测迭代的低分辨率掩码逻辑。
masks_two, mask_scores, _ = predictor.predict(
point_coords=input_point,
point_labels=input_label,
mask_input=mask_input[None, :, :],
multimask_output=True,
)
for i, (mask, score) in enumerate(zip(masks_two, mask_scores)):
plt.figure(figsize=(10, 10))
show_mask(mask, plt.gca())
plt.show()
Contributor guide
Research direction
The issue provides no target file; start by reading SamPredictor.predict and the example notebook or demo that uses point_coords, point_labels, and mask_input. Reproduce the reported single-point flow, then define a clear expected result for multiple points and deletions before assessing completion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, numpy, python
- Domain
- computer-vision, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100