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)
# 生成Token
text = clip.tokenize(["流程图", "a dog", "a cat"]).to(device)
print(text.size())

with torch.no_grad():
		# 获取Image Embeding
    image_features = model.encode_image(image)
		# 获取Image Embeding
    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]]