facebookresearch / facebookresearch/sam2
USING MASK PROMPTS INSTEAD OF BOX OR POINTS
- Dominant language
- Jupyter Notebook
- Stars
- 19.9k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
I already have my grey scale images and i want to use it as an input instead of using points. how can i do that? , Here is my code block.
prompts = {}
ann_frame_idx = 0 # The frame index we interact with
ann_obj_id = 2 # Give a unique ID to each object we interact with (it can be any integer)
# Add two positive clicks at (x, y) = (200, 900) and (50, 600) for the traversable road
points = np.array([[590, 500],[500,700],[250,980],[400,600]], dtype=np.float32)
labels = np.array([1,1,1,0], np.int32) # Two labels, both positive clicks
prompts[ann_obj_id] = points, labels # Store the points and labels for ann_obj_id
# Add the new points or box
_, out_obj_ids, out_mask_logits = predictor.add_new_points_or_box(
inference_state=inference_state,
frame_idx=ann_frame_idx,
obj_id=ann_obj_id,
points=points,
labels=labels,
)
# Show the results on the current (interacted) frame
plt.figure(figsize=(9, 6))
plt.title(f"frame {ann_frame_idx}")
# Open and display the current frame image
plt.imshow(Image.open(os.path.join(video_dir, frame_names[ann_frame_idx])))
# Show the input points
show_points(points, labels, plt.gca())
# Iterate through output object IDs and display their prompts and masks
for i, out_obj_id in enumerate(out_obj_ids):
# Show the points corresponding to the current object
show_points(*prompts[out_obj_id], plt.gca())
# Show the mask for the current object
show_mask((out_mask_logits[i] > 0.0).cpu().numpy(), plt.gca(), obj_id=out_obj_id)..... i have attached a grey scale image

Contributor guide
Assessment
This issue has not been assessed yet.