IDEA-Research/Grounded-SAM-2

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

Closed this issue · 3 comments

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

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

@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

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