segment-anything
segment-anything copied to clipboard
How can multiple points and deletions be done simultaneously?
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_registrymodel_type 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()