Closed wudizuixiaosa closed 1 year ago
Thanks for your attention to our work! We will adapt our code to the latest clip and open_clip.
Hi @wudizuixiaosa , I have uploaded an example code for inference: https://github.com/microsoft/Cream/blob/main/TinyCLIP/inference.py, whose usage is similar to CLIP.
Hi @wudizuixiaosa , I have uploaded an example code for inference: https://github.com/microsoft/Cream/blob/main/TinyCLIP/inference.py, whose usage is similar to CLIP.
Thank you!sir
import 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)
print("Label probs:", probs) # prints: [[0.9927937 0.00421068 0.00299572]] like this,I only need to add a small amount of code to apply it to my code and provide assistance