-  
 -   Notifications  
You must be signed in to change notification settings  - Fork 49.1k
 
Added Image Segmentation which fixes #13516 #13518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
78a95e3 4233486 a955074 5e8c079 fd4ef37 6b33680 648ed53 05c231e File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…m2.py
- Loading branch information
 
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|      |  @@ -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): | ||
|   There was a problem hiding this comment. Choose a reason for hiding this commentThe 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  Please provide return type hint for the function:  Please provide type hint for the parameter:  Please provide type hint for the parameter:  Please provide type hint for the parameter:  Please provide type hint for the parameter:   |  ||
|      |  @@ -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]) | ||
|   |  ||
|      |  @@ -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    |  ||
    |  ||
| """Demonstrate segmentation using multiple point prompts""" | ||
| print("=== Multiple Points Prompt ===") | ||
|   |  ||
|      |  @@ -319,10 +317,10 @@ | |
| # Display all masks together | ||
| plt.figure(figsize=(10, 10)) | ||
| plt.imshow(image) | ||
| for i, mask in enumerate(masks): | ||
| 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() | ||
|      |  @@ -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 | ||
| ) | ||
|   |  ||
|      |  ||
There was a problem hiding this comment.
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 functionshow_maskPlease provide type hint for the parameter:
maskPlease provide type hint for the parameter:
axPlease provide type hint for the parameter:
random_colorPlease provide type hint for the parameter:
borders