mirror of
https://github.com/openai/CLIP.git
synced 2026-11-05 01:37:26 +00:00
[GH-ISSUE #347] RuntimeError: The size of tensor a (768) must match the size of tensor b (7) at non-singleton dimension 2. #299
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#299
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 @sankyde on GitHub (Apr 10, 2023).
Original GitHub issue: https://github.com/openai/CLIP/issues/347
This is the program I am trying to write. It's simple but I still get this error.
Steps to Reproduce:
from PIL import Image
import requests
import torch
import clip
clip.available_models()
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
model, preprocess = clip.load("ViT-B/32")
image_input=torch.tensor(preprocess(image)).cuda()
text_tokens=clip.tokenize(
["This is an image of two cats sleeping on a pink blanket"])
with torch.no_grad():
image_features=model.encode_image(image_input).float()
text_tokens=model.encode_text(text_tokens).float()
@adtygan commented on GitHub (May 4, 2023):
In Line 1
.unsqueeze(0)needs to called (refer example in https://github.com/openai/CLIP#usage)In Line 2
.cuda()needs to be added as well to ensure bothimage_featuresandtext_tokensare on the same device