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

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

Open
whenmoon opened this issue Nov 20, 2023 · 6 comments

Comments

@whenmoon
Copy link

Hi! Both the web form and API calls to Replicate fail when I run this model: https://replicate.com/schananas/grounded_sam

Running prediction: 3341693a-59dd-4e9d-b89f-2ba89f3ab53c...
Traceback (most recent call last):
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/cog/server/worker.py", line 222, in _predict
for r in result:
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 43, in generator_context
response = gen.send(None)
File "/src/predict.py", line 78, in predict
annotated_picture_mask, neg_annotated_picture_mask, mask, inverted_mask = run_grounding_sam(image,
File "/src/grounded_sam.py", line 100, in run_grounding_sam
neg_segmented_frame_masks = segment(image_source, sam_predictor, boxes=neg_detected_boxes)
File "/src/grounded_sam.py", line 55, in segment
masks, _, _ = sam_model.predict_torch(
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/src/weights/segment-anything/segment_anything/predictor.py", line 229, in predict_torch
low_res_masks, iou_predictions = self.model.mask_decoder(
File "/root/.pyenv/versions/3.10.13/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
File "/src/weights/segment-anything/segment_anything/modeling/mask_decoder.py", line 94, in forward
masks, iou_pred = self.predict_masks(
File "/src/weights/segment-anything/segment_anything/modeling/mask_decoder.py", line 144, in predict_masks
masks = (hyper_in @ upscaled_embedding.view(b, c, h * w)).view(b, -1, h, w)
RuntimeError: 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
@whenmoon
Copy link
Author

Having tested this again, it works only with the default photo on Replicate, any other photo, it fails. I've tried different formats, color profiles, sizes, compression levels, but alway hit this error either via the replicate web form or the Replicate API. I guess it has somthing to do with the source image but I can't figure out what.. Any help much appreciated!

@schananas
Copy link
Owner

Thanks for reporting, Il check it in following days

@whenmoon
Copy link
Author

Thanks for reporting, Il check it in following days

Ok thanks! 👌🏽

@smyja
Copy link

smyja commented Nov 25, 2023

I just tried it, same problem.

@smyja
Copy link

smyja commented Nov 25, 2023

Having tested this again, it works only with the default photo on Replicate, any other photo, it fails. I've tried different formats, color profiles, sizes, compression levels, but alway hit this error either via the replicate web form or the Replicate API. I guess it has somthing to do with the source image but I can't figure out what.. Any help much appreciated!

I think i have figured out the problem, you have to define the correct negative prompt(items you don't want masked).

@whenmoon
Copy link
Author

whenmoon commented Nov 26, 2023

Having tested this again, it works only with the default photo on Replicate, any other photo, it fails. I've tried different formats, color profiles, sizes, compression levels, but alway hit this error either via the replicate web form or the Replicate API. I guess it has somthing to do with the source image but I can't figure out what.. Any help much appreciated!

I think i have figured out the problem, you have to define the correct negative prompt(items you don't want masked).

Hi, I'm not sure because the script has a default negative prompt and running it on Replicate doesn't fail if you remove it

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

3 participants