Skip to content

Commit 5e8c079

Browse files
authored
Update and rename Image_Segmentation_SAM2.py to image_segmentation_sam2.py
1 parent a955074 commit 5e8c079

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

computer_vision/Image_Segmentation_SAM2.py renamed to computer_vision/image_segmentation_sam2.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setup_device():
3838

3939

4040
# Visualization functions
41-
np.random.seed(3)
41+
rng = np.random.default_rng(3)
4242

4343

4444
def show_mask(mask, ax, random_color=False, borders=True):
@@ -52,7 +52,7 @@ def show_mask(mask, ax, random_color=False, borders=True):
5252
borders: Whether to draw mask borders
5353
"""
5454
if random_color:
55-
color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
55+
color = np.concatenate([rng.random(3), np.array([0.6])], axis=0)
5656
else:
5757
color = np.array([30 / 255, 144 / 255, 255 / 255, 0.6])
5858

@@ -221,9 +221,7 @@ def demonstrate_point_prompt(predictor, image):
221221
return masks, scores, logits
222222

223223

224-
def demonstrate_multiple_points(
225-
predictor, image, previous_masks, previous_scores, previous_logits
226-
):
224+
def demonstrate_multiple_points(predictor, image, previous_masks, previous_scores, previous_logits):
227225
"""Demonstrate segmentation using multiple point prompts"""
228226
print("=== Multiple Points Prompt ===")
229227

@@ -321,8 +319,8 @@ def demonstrate_batched_prompts(predictor, image):
321319
plt.imshow(image)
322320
for i, mask in enumerate(masks):
323321
show_mask(mask.squeeze(0), plt.gca(), random_color=True)
324-
for box in input_boxes:
325-
show_box(box, plt.gca())
322+
for mask in masks:
323+
show_mask(mask.squeeze(0), plt.gca(), random_color=True)
326324
plt.axis("off")
327325
plt.title("Batched Prompts - Multiple Objects")
328326
plt.show()
@@ -360,7 +358,7 @@ def demonstrate_batched_images(predictor):
360358

361359
# Process batch
362360
predictor.set_image_batch(img_batch)
363-
masks_batch, scores_batch, _ = predictor.predict_batch(
361+
masks_batch, _ , _ = predictor.predict_batch(
364362
None, None, box_batch=boxes_batch, multimask_output=False
365363
)
366364

0 commit comments

Comments
 (0)