license: apache-2.0
inference: false
pipeline_tag: zero-shot-image-classification
pipeline_tag: feature-extraction
inference:
parameters:
tags:
- clip
- zh
- image-text
- feature-extraction
太乙-CLIP-RoBERTa-102M-ViT-L-中文版
简介
首个开源的中文CLIP模型,基于1.23亿图文对进行预训练,文本编码器采用RoBERTa-base架构。
模型分类
需求 |
任务 |
系列 |
模型 |
参数规模 |
附加特性 |
特殊领域 |
多模态 |
太乙 |
CLIP(RoBERTa) |
1.02亿 |
中文支持 |
模型信息
我们严格遵循CLIP的实验配置,以获取强大的视觉-语言联合表征能力。在构建中文版CLIP时,文本编码器选用中文RoBERTa-wwm,视觉编码器采用open_clip中的ViT-L-14架构。为提升预训练效率与稳定性,我们冻结视觉编码器参数,仅微调语言编码器。训练数据整合了悟空数据集(1亿样本)与Zero数据集(2300万样本),在A100x32集群上完成24轮训练(耗时6天)。据我们所知,这是Huggingface社区首个开源的中文CLIP实现。
下游任务表现
零样本图像分类
模型 |
数据集 |
Top1准确率 |
Top5准确率 |
太乙-CLIP-RoBERTa-102M-ViT-L-中文版 |
ImageNet1k-CN |
55.04% |
81.75% |
零样本文本-图像检索
模型 |
数据集 |
Top1 |
Top5 |
Top10 |
太乙-CLIP-RoBERTa-102M-ViT-L-中文版 |
Flickr30k-CNA测试集 |
58.32% |
82.96% |
89.40% |
太乙-CLIP-RoBERTa-102M-ViT-L-中文版 |
COCO-CN测试集 |
55.27% |
81.10% |
90.78% |
太乙-CLIP-RoBERTa-102M-ViT-L-中文版 |
悟空50k数据集 |
64.95% |
91.77% |
96.28% |
使用示例
from PIL import Image
import requests
import open_clip
import torch
from transformers import BertModel, BertConfig, BertTokenizer
from transformers import CLIPProcessor, CLIPModel
import numpy as np
query_texts = ["一只猫", "一只狗",'两只猫', '两只老虎','一只老虎']
text_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese")
text_encoder = BertModel.from_pretrained("IDEA-CCNL/Taiyi-CLIP-RoBERTa-102M-ViT-L-Chinese").eval()
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
clip_model, _, processor = open_clip.create_model_and_transforms('ViT-L-14', pretrained='openai')
clip_model = clip_model.eval()
text = text_tokenizer(query_texts, return_tensors='pt', padding=True)['input_ids']
image = processor(Image.open(requests.get(url, stream=True).raw)).unsqueeze(0)
with torch.no_grad():
image_features = clip_model.encode_image(image)
text_features = text_encoder(text)[1]
image_features = image_features / image_features.norm(dim=1, keepdim=True)
text_features = text_features / text_features.norm(dim=1, keepdim=True)
logit_scale = clip_model.logit_scale.exp()
logits_per_image = logit_scale * image_features @ text_features.t()
logits_per_text = logits_per_image.t()
probs = logits_per_image.softmax(dim=-1).cpu().numpy()
print(np.around(probs, 3))
引用文献
如果研究工作使用了本模型,请引用我们的论文:
@article{fengshenbang,
author = {张嘉旭等23位作者},
title = {封神榜1.0:中文认知智能基础体系},
journal = {CoRR},
volume = {abs/2209.02970},
year = {2022}
}
或引用项目主页:
@misc{封神榜大模型,
title={封神榜大模型},
author={IDEA-CCNL},
year={2021},
howpublished={\url{https://github.com/IDEA-CCNL/Fengshenbang-LM}},
}