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

ValueError: mask must be a 3D np.ndarray with shape (1, H, W), but got shape (1, 1, 1024, 768) when using prompt "shirt" in Grounded SAM 2 #5

Closed
sahal-786 opened this issue Aug 8, 2024 · 3 comments

Comments

@sahal-786
Copy link

When using Grounded SAM 2 to process an image with the prompt "shirt," I encountered a ValueError. The error indicates that the mask must be a 3D np.ndarray with shape (1, H, W), but the provided mask has shape (1, 1, 1024, 768).
ValueError: mask must be a 3D np.ndarray with shape (1, H, W), but got shape (1, 1, 1024, 768)

prompt = "shirt."

02_1E0A0878

@rentainhe
Copy link
Collaborator

rentainhe commented Aug 8, 2024

We've encountered the same issue, we will fix it as soon as possible

@rentainhe
Copy link
Collaborator

@sahal-786 We've already fixed this bug with the following changes:

change the following code

if masks.ndim == 3:
    masks = masks[None]
    scores = scores[None]
    logits = logits[None]
if masks.ndim == 4:
    masks = masks.squeeze(1)

to:

if masks.ndim == 4:
    masks = masks.squeeze(1)

And the segmentation result is as follows:
grounded_sam2_annotated_image_with_mask

@rentainhe
Copy link
Collaborator

I will close this issue because the bug has already been fixed, feel free to reopen it if you need any other helps.

rentainhe pushed a commit that referenced this issue Dec 21, 2024
Fix typo in README: "Aything" corrected to "Anything"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants