mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #189] RuntimeError: The size of tensor a (2) must match the size of tensor b (50) at non-singleton dimension 1 #164
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openai/CLIP#164
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @RylanSchaeffer on GitHub (Nov 28, 2021).
Original GitHub issue: https://github.com/openai/CLIP/issues/189
When I load the ViT-B/32 model, like so,
And then construct a CIFAR100 dataloader using preprocess as the dataloader, I have input tensors of shape
(batch size, 3, 32, 32). But when I try callingI get
RuntimeError: The size of tensor a (2) must match the size of tensor b (50) at non-singleton dimension 1. The error is caused by line 224 in model.py:At this line,
xhas shape(batch size, 2, 768)whereasself.positional_embeddinghas shape(batch size, 768).I don't know what the correct behavior is to know whether
xshould not have dimension 1 orself.positional_embeddingshould have dimension 1 or something else entirely.Could someone please clarify?
@RylanSchaeffer commented on GitHub (Nov 28, 2021):
The comment on line 223 suggests that
xshould indeed be 3 dimensional, which suggests to me that the positional embedding is wrong. Is this correct?@Evm7 commented on GitHub (Jan 13, 2022):
Hey @RylanSchaeffer , I am finding a simillar problem when changing the input size of the model. Did you finally manage to find the proper solution?
@RylanSchaeffer commented on GitHub (Jan 13, 2022):
@Evm7 unfortunately I can't remember :(
@jogisuda commented on GitHub (Jan 28, 2022):
Facing exactly the same issue here
@jogisuda commented on GitHub (Jan 28, 2022):
Found the solution. My problem was the size of the images: I had batches of dimension (16, 3, 32, 32) (16 images per batch, 3 channels, 32 height/width). Got it working when changed the Transforms to resize to dimension 224. So, final shape became (16, 3, 224, 224). Hope it helps!
@Dinosaurcubs commented on GitHub (Dec 25, 2023):
in other words, the input shape must be (B, 3 , 224, 224) ?