Skip to content

Question on the example: #380

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

Closed
shersoni610 opened this issue Jul 22, 2023 · 1 comment
Closed

Question on the example: #380

shersoni610 opened this issue Jul 22, 2023 · 1 comment

Comments

@shersoni610
Copy link

Hello,

I see the following example on the page:

Qs: (1) we are calculate image and text features, but they are not being used in the code.
(2) Are the arguments to the model (image,text) or (image_feature, text_features)

Thanks

mport torch
import clip
from PIL import Image

device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = clip.load("ViT-B/32", device=device)

image = preprocess(Image.open("CLIP.png")).unsqueeze(0).to(device)
text = clip.tokenize(["a diagram", "a dog", "a cat"]).to(device)

with torch.no_grad():
image_features = model.encode_image(image)
text_features = model.encode_text(text)

logits_per_image, logits_per_text = model(image, text)
probs = logits_per_image.softmax(dim=-1).cpu().numpy()

print("Label probs:", probs) # prints: [[0.9927937 0.00421068 0.00299572]]

@jongwook
Copy link
Collaborator

Those are intentional. Please see:

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

2 participants