Skip to content
Prev Previous commit
Next Next commit
Update and rename Image_Segmentation_SAM2.py to image_segmentation_sa…
…m2.py
  • Loading branch information
NANDAGOPALNG authored Oct 15, 2025
commit 5e8c0796943bede554b5a0d83f0a1b8afd0980b7
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# Visualization functions
np.random.seed(3)
rng = np.random.default_rng(3)


def show_mask(mask, ax, random_color=False, borders=True):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: show_mask. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file computer_vision/image_segmentation_sam2.py, please provide doctest for the function show_mask

Please provide type hint for the parameter: mask

Please provide type hint for the parameter: ax

Please provide type hint for the parameter: random_color

Please provide type hint for the parameter: borders

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file computer_vision/image_segmentation_sam2.py, please provide doctest for the function show_mask

Please provide return type hint for the function: show_mask. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: mask

Please provide type hint for the parameter: ax

Please provide type hint for the parameter: random_color

Please provide type hint for the parameter: borders

Expand All @@ -52,7 +52,7 @@
borders: Whether to draw mask borders
"""
if random_color:
color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
color = np.concatenate([rng.random(3), np.array([0.6])], axis=0)
else:
color = np.array([30 / 255, 144 / 255, 255 / 255, 0.6])

Expand Down Expand Up @@ -221,9 +221,7 @@
return masks, scores, logits


def demonstrate_multiple_points(
predictor, image, previous_masks, previous_scores, previous_logits
):
def demonstrate_multiple_points(predictor, image, previous_masks, previous_scores, previous_logits):

Check failure on line 224 in computer_vision/image_segmentation_sam2.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

computer_vision/image_segmentation_sam2.py:224:89: E501 Line too long (100 > 88)

Check failure on line 224 in computer_vision/image_segmentation_sam2.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (ARG001)

computer_vision/image_segmentation_sam2.py:224:51: ARG001 Unused function argument: `previous_masks`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: demonstrate_multiple_points. If the function does not return a value, please provide the type hint as: def function() -> None:

As there is no test file in this pull request nor any test function or class in the file computer_vision/image_segmentation_sam2.py, please provide doctest for the function demonstrate_multiple_points

Please provide type hint for the parameter: predictor

Please provide type hint for the parameter: image

Please provide type hint for the parameter: previous_masks

Please provide type hint for the parameter: previous_scores

Please provide type hint for the parameter: previous_logits

"""Demonstrate segmentation using multiple point prompts"""
print("=== Multiple Points Prompt ===")

Expand Down Expand Up @@ -319,10 +317,10 @@
# Display all masks together
plt.figure(figsize=(10, 10))
plt.imshow(image)
for i, mask in enumerate(masks):

Check failure on line 320 in computer_vision/image_segmentation_sam2.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (B007)

computer_vision/image_segmentation_sam2.py:320:9: B007 Loop control variable `i` not used within loop body
show_mask(mask.squeeze(0), plt.gca(), random_color=True)
for box in input_boxes:
show_box(box, plt.gca())
for mask in masks:
show_mask(mask.squeeze(0), plt.gca(), random_color=True)
plt.axis("off")
plt.title("Batched Prompts - Multiple Objects")
plt.show()
Expand Down Expand Up @@ -360,7 +358,7 @@

# Process batch
predictor.set_image_batch(img_batch)
masks_batch, scores_batch, _ = predictor.predict_batch(
masks_batch, _ , _ = predictor.predict_batch(
None, None, box_batch=boxes_batch, multimask_output=False
)

Expand Down
Loading