Skip to content
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

Sam2 multi polygons #593

Merged
merged 25 commits into from
Aug 27, 2024
Merged

Sam2 multi polygons #593

merged 25 commits into from
Aug 27, 2024

Conversation

probicheaux
Copy link
Collaborator

@probicheaux probicheaux commented Aug 22, 2024

Description

BREAKING CHANGE: changes format of sam2response

Allow inference to output multiple polygons from cv2.findContours
Also adds not-a-point at [0, 0] to empty prompts because sam2 performs better:

The below shows unprompted sam2 with different settings.
Before this pr:
Screenshot 2024-08-22 at 5 55 49 PM

After adding multiple masks to return:
Screenshot 2024-08-22 at 6 00 00 PM

After adding multiple masks with dummy not-a-point
Screenshot 2024-08-22 at 6 03 13 PM

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this change been tested, please provide a testcase or example of how you tested the change?

Staging

Any specific deployment considerations

n/a

Docs

  • Docs updated? What were the changes:

@probicheaux
Copy link
Collaborator Author

@PawelPeczek-Roboflow can you take a look at this? in particular, wondering if what I did here is ok -- not totally allowed by the types but I am not sure if constructing the full workflow image type here is overkill when the function needs just the height/width of the image

@yeldarby
Copy link
Contributor

Also adds not-a-point at [0, 0] to empty prompts because sam2 performs better:

What'd happen if we did a positive point at the centerpoint of the image instead? My guess is in a lot of images that'd produce a much better result given the most important object is often centered.

@probicheaux
Copy link
Collaborator Author

@yeldarby to be clear, not a point is a special padding label, not a negative poitn

I'd rather let the user decide to put a positive point in the middle of the image if they want it, otherwise let sam figure out what it should segment (even tho those results tend to be bad)

@yeldarby
Copy link
Contributor

I understand. But defaults are powerful. The special point doesn’t seem like it’d ever be a better default than the center point would be (just like a null set doesn’t seem better than the special point).

Agree that almost always the user should be giving a prompt anyway, but the case we’re considering here is what we should do when they don’t.

@probicheaux
Copy link
Collaborator Author

. The special point doesn’t seem like it’d ever be a better default than the center point would be (just like a null set doesn’t seem better than the special point)

hmm, I would think it'd be better on images where the object in focus isn't in the center of the image

as for the null set, I mean -- theoretically it should produce the same output as adding in a random point and labeling it as not a point, but for some reason the prompt encoder seems to work better with this input.

@probicheaux
Copy link
Collaborator Author

@PawelPeczek-Roboflow tests are passing now

@yeldarby
Copy link
Contributor

hmm, I would think it'd be better on images where the object in focus isn't in the center of the image

I think it'd be similar, right? (bad in both cases since the -1 point and the center point both wouldn't be signaling to highlight the salient object)

Copy link
Collaborator

@PawelPeczek-Roboflow PawelPeczek-Roboflow left a comment

Choose a reason for hiding this comment

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

LGTM, please add those small adjustments

@probicheaux
Copy link
Collaborator Author

@PawelPeczek-Roboflow your comments have been addressed!

@probicheaux probicheaux merged commit 49b131e into main Aug 27, 2024
58 checks passed
@probicheaux probicheaux deleted the sam2-multi-polygons branch August 27, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants