facebookresearch / facebookresearch/segment-anything
RuntimeError when using batch size > 1
- Dominant language
- Jupyter Notebook
- Stars
- 54.9k
- Forks
- 6.4k
- PR merge metrics
- No merged PRs in 30d
Description
I get this error when batch size if larger than 1
`RuntimeError: The size of tensor a (2) must match the size of tensor b (4) at non-singleton dimension 0`
My sparse embedding size is [2,0,156] (empty with batch size 2)
My dense embedding size is [2,256,64,64] (batch size 2)
```
output_tokens = output_tokens.unsqueeze(0).expand(sparse_prompt_embeddings.size(0), -1, -1)
tokens = torch.cat((output_tokens, sparse_prompt_embeddings), dim=1)
src = torch.repeat_interleave(image_embeddings, tokens.shape[0], dim=0)
src = src + dense_prompt_embeddings
```
So the repeat_interleave extend the image_embeddings to 4 which is actually larger than the batch size
Am i missing something? or the repeat interleave is redundant?
Contributor guide
Research direction
Start at the code path containing the shown prompt-embedding and image-embedding operations, then reproduce the issue with batch size 2 and inspect the tensor shapes before concatenation and addition. Done means batched sparse and dense embeddings combine without a dimension mismatch and the existing batch-size-one behavior still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100