OFA-Sys / Chinese-CLIP

Chinese version of CLIP which achieves Chinese cross-modal retrieval and representation generation.
MIT License
4.32k stars 448 forks source link

已有图文特征向量,如何使用clip-retrieval搭建demo #216

Closed victorxst closed 10 months ago

victorxst commented 11 months ago

您好,已经获取到图文特征向量,如何使用clip-retrieval搭建demo呢?

yangapku commented 11 months ago

您好,您可以参见clip-retrieval 本身的readme进行搭建服务哈,我们也是完全复用该库搭建的后端服务(前端是modelscope的同学帮忙准备的) https://github.com/rom1504/clip-retrieval

victorxst commented 11 months ago

chinese-clip获取到图文特征json数据后,如何在clip-retrieval使用呢,是使用img2dataset创建数据集吗?

victorxst commented 11 months ago

您好,示例中只介绍了get_similarity方法。请问有,已有文字搜索图片的方法吗,或者已有图片搜索图片的方法

import torch
from PIL import Image
import cn_clip.clip as clip
from cn_clip.clip import load_from_name

device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = load_from_name('/home/chinese-clip/data/pretrained_weights/clip_cn_vit-b-16.pt',
                                    device=device, vision_model_name="ViT-B-16", text_model_name="RoBERTa-wwm-ext-base-chinese",
                                   input_resolution=224)
model.eval()

text = "红鞋"

text_input = clip.tokenize([text]).to(device)
with torch.no_grad():
    text_features = model.encode_text(text_input)
    text_features /= text_features.norm(dim=-1, keepdim=True)

在CLIP类中并没有发现此类方法

IF-chan commented 6 months ago

chinese-clip获取到图文特征json数据后,如何在clip-retrieval使用呢,是使用img2dataset创建数据集吗?

请问你是怎么做的