Skip to content

Fix crash when negative prompt detects no objects#4

Open
jkukul wants to merge 1 commit intoschananas:mainfrom
jkukul:fix-missing-negative-prompt
Open

Fix crash when negative prompt detects no objects#4
jkukul wants to merge 1 commit intoschananas:mainfrom
jkukul:fix-missing-negative-prompt

Conversation

@jkukul
Copy link

@jkukul jkukul commented Nov 15, 2025

When the negative prompt doesn't detect any objects in the image, GroundingDINO returns an empty tensor which causes SAM to fail with a reshape error. Now we check if boxes were detected before attempting segmentation. If no negative objects are detected, we skip the negative mask processing and use only the positive mask, which is the correct behavior since there's nothing to subtract.

Fixes #1

When the negative prompt doesn't detect any objects in the image,
GroundingDINO returns an empty tensor which causes SAM to fail with
a reshape error. Now we check if boxes were detected before attempting
segmentation. If no negative objects are detected, we skip the negative
mask processing and use only the positive mask, which is the correct
behavior since there's nothing to subtract.
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

Successfully merging this pull request may close these issues.

Cannot reshape tensor of 0 elements into shape [0, -1, 256, 256] because the unspecified dimension size -1 can be any value and is ambiguous

1 participant