github地址
GitHub - openai/CLIP: Contrastive Language-Image Pretraining
创建python环境
conda create -n CLIP python=3.8
安装pytorch和torchvision
conda install --yes -c pytorch pytorch=1.7.1 torchvision cudatoolkit=11.0
下载包:ftfy regex tqdm 和CLIP
pip install ftfy regex tqdm
pip install git+https://github.com/openai/CLIP.git
应用举例
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.jpg")).unsqueeze(0).to(device)
text = clip.tokenize(["