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

Issue with inference values with 'hf-hub:laion/CLIP-convnext_xxlarge-laion2B-s34B-b82K-augreg' #865

Closed
dbugger29 opened this issue Apr 25, 2024 · 3 comments

Comments

@dbugger29
Copy link

dbugger29 commented Apr 25, 2024

Can you help me with the following:

I receive different values for the same image and with the same class names.

import torch
import pickle
from PIL import Image
import open_clip

model, _, preprocess = open_clip.create_model_and_transforms('hf-hub:laion/CLIP-convnext_xxlarge-laion2B-s34B-b82K-augreg')
tokenizer = open_clip.get_tokenizer('hf-hub:laion/CLIP-convnext_xxlarge-laion2B-s34B-b82K-augreg')
image = preprocess(Image.open("<some_image>")).unsqueeze(0)
text = tokenizer(["a diagram", "a dog", "a cat"])
with torch.no_grad(), torch.cuda.amp.autocast():
    image_features = model.encode_image(image)
    text_features = model.encode_text(text)
    image_features /= image_features.norm(dim=-1, keepdim=True)
    text_features /= text_features.norm(dim=-1, keepdim=True)
    text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)

print("Label probs:", text_probs)  # prints: [[1., 0., 0.]]

These are the results after I ran the same code twice:

Label probs: tensor([[4.4378e-04, 6.0942e-01, 3.9013e-01]])
Label probs: tensor([[3.7052e-04, 6.6962e-01, 3.3001e-01]])

This does not seems to be the case with other models. Any help would be appreciated 🙇‍♀️

@rwightman
Copy link
Collaborator

@dbugger29 you are right, this had me puzzled for a second, you need model.eval() ... open_clip models default to .train() mode like many torch model libs. Why is this needed? convnext doesn't have batchnorm like the Resnet models, but it does have stochastic depth active by default which will inject randomness in train mode.

@dbugger29
Copy link
Author

Thank you :D

@dbugger29
Copy link
Author

Hello,
@rwightman, I come back with a similar issue with: ViT-H-14-378-quickgelu. Can you help me with this also?
Also, I am trying the latest models from https://github.com/facebookresearch/MetaCLIP/, I cannot load:
open_clip.create_model_and_transforms('ViT-bigG-14-quickgelu', pretrained='metaclip_fullcc')
Any kind of help would be appreciated :D
thank you

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