This project aims to provide a better Chinese CLIP model. The training data used in this project consists of publicly accessible image URLs and related Chinese text descriptions, totaling 400 million. After screening, we ultimately used 100 million data for training.
This project is produced by QQ-ARC Joint Lab, Tencent PCG. For more detailed information, please refer to the
main page of the QA-CLIP project. We have also open-sourced our code on GitHub,
QA-CLIP, and welcome to star!
We conducted zero-shot tests on
MUGE Retrieval,
Flickr30K-CN, and
COCO-CN datasets for image-text retrieval tasks. For the image zero-shot classification task, we tested on the ImageNet dataset. The test results are shown in the table below:
1from PIL import Image
2import requests
3from transformers import ChineseCLIPProcessor, ChineseCLIPModel
4
5model = ChineseCLIPModel.from_pretrained("TencentARC/QA-CLIP-ViT-L-14")
6processor = ChineseCLIPProcessor.from_pretrained("TencentARC/QA-CLIP-ViT-L-14")
7
8url = "https://clip-cn-beijing.oss-cn-beijing.aliyuncs.com/pokemon.jpeg"
9image = Image.open(requests.get(url, stream=True).raw)
10# Squirtle, Bulbasaur, Charmander, Pikachu in English
11texts = ["杰尼龟", "妙蛙种子", "小火龙", "皮卡丘"]
12
13# compute image feature
14inputs = processor(images=image, return_tensors="pt")
15image_features = model.get_image_features(**inputs)
16image_features = image_features / image_features.norm(p=2, dim=-1, keepdim=True) # normalize
17
18# compute text features
19inputs = processor(text=texts, padding=True, return_tensors="pt")
20text_features = model.get_text_features(**inputs)
21text_features = text_features / text_features.norm(p=2, dim=-1, keepdim=True) # normalize
22
23# compute image-text similarity scores
24inputs = processor(text=texts, images=image, return_tensors="pt", padding=True)
25outputs = model(**inputs)
26logits_per_image = outputs.logits_per_image # this is the image-text similarity score
27probs = logits_per_image.softmax(dim=1)
The project code is based on implementation of
Chinese-CLIP, and we are very grateful for their outstanding open-source contributions.