Open laitianan opened 3 months ago
you can try the code next.
model, preprocess = clip.from_pretrained("model_path")
you can try the code next.
model, preprocess = clip.from_pretrained("model_path")
model, preprocess = clip.from_pretrained(model_path)
AttributeError: module 'cn_clip.clip' has no attribute 'from_pretrained'
you can try the code next.
model, preprocess = clip.from_pretrained("model_path")
model, preprocess = clip.from_pretrained(model_path)
AttributeError: module 'cn_clip.clip' has no attribute 'from_pretrained'
try clip.load() function
提前设置好你模型文件的位置,然后用下面的代码:
clip_path = ''/data/model/epoch2.pt'
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = load_from_name(clip_path, device=device, vision_model_name="ViT-B-16", text_model_name="RoBERTa-wwm-ext-base-chinese", input_resolution=224)
提前设置好你模型文件的位置,然后用下面的代码:
clip_path = ''/data/model/epoch2.pt' device = "cuda" if torch.cuda.is_available() else "cpu" model, preprocess = load_from_name(clip_path, device=device, vision_model_name="ViT-B-16", text_model_name="RoBERTa-wwm-ext-base-chinese", input_resolution=224)
model, preprocess = load_from_name(clip_path, device=device, vision_model_name="ViT-B-16",
TypeError: load_from_name() got an unexpected keyword argument 'vision_model_name' 好像不太行
提前设置好你模型文件的位置,然后用下面的代码:
clip_path = ''/data/model/epoch2.pt' device = "cuda" if torch.cuda.is_available() else "cpu" model, preprocess = load_from_name(clip_path, device=device, vision_model_name="ViT-B-16", text_model_name="RoBERTa-wwm-ext-base-chinese", input_resolution=224)
model, preprocess = load_from_name(clip_path, device=device, vision_model_name="ViT-B-16",
TypeError: load_from_name() got an unexpected keyword argument 'vision_model_name' 好像不太行
没有这个vision_model_name?你导入cn_clip了吗
import cn_clip.clip as clip
from cn_clip.clip import load_from_name, available_models
import torch from PIL import Image
import cn_clip.clip as clip from cn_clip.clip import load_from_name, available_models print("Available models:", available_models())
Available models: ['ViT-B-16', 'ViT-L-14', 'ViT-L-14-336', 'ViT-H-14', 'RN50']
device = "cuda" if torch.cuda.is_available() else "cpu" model, preprocess = load_from_name("ViT-B-16", device=device, download_root='./') model.eval() image = preprocess(Image.open("examples/pokemon.jpeg")).unsqueeze(0).to(device) text = clip.tokenize(["杰尼龟", "妙蛙种子", "小火龙", "皮卡丘"]).to(device)
with torch.no_grad(): image_features = model.encode_image(image) text_features = model.encode_text(text)
对特征进行归一化,请使用归一化后的图文特征用于下游任务
print("Label probs:", probs) # [[1.268734e-03 5.436878e-02 6.795761e-04 9.436829e-01]]