🚀 太乙CLIP-RoBERTa-326M-ViT-H-中文
太乙CLIP-RoBERTa-326M-ViT-H-中文是首个开源的中文CLIP模型,它在1.23亿图文对上进行预训练,文本端采用RoBERTa-large,能够获得强大的视觉 - 语言表征。
🚀 快速开始
模型信息
属性 |
详情 |
模型类型 |
特殊需求下的多模态模型,属于太乙系列的CLIP (RoBERTa),参数为326M,使用了ViT-H作为视觉提取器 - 中文 |
训练数据 |
使用Noah-Wukong数据集(100M)和Zero数据集(23M)作为预训练数据集,在悟空数据集和zero数据集上预训练24轮,在A100x32上训练了8天 |
下游效果
零样本分类
模型 |
数据集 |
Top1 |
Top5 |
Taiyi-CLIP-RoBERTa-326M-ViT-H-Chinese |
ImageNet1k-CN |
54.35% |
80.64% |
零样本文本到图像检索
模型 |
数据集 |
Top1 |
Top5 |
Top10 |
Taiyi-CLIP-RoBERTa-326M-ViT-H-Chinese |
Flickr30k-CNA-test |
60.82% |
85.00% |
91.04% |
Taiyi-CLIP-RoBERTa-326M-ViT-H-Chinese |
COCO-CN-test |
60.02% |
83.95% |
93.26% |
Taiyi-CLIP-RoBERTa-326M-ViT-H-Chinese |
wukong50k |
66.85% |
92.81% |
96.69% |
✨ 主要特性
- 首个开源的中文CLIP模型,在多模态任务上表现出色。
- 采用强大的视觉 - 语言表征学习方法,遵循CLIP的实验设置。
- 使用特定的语言编码器和视觉编码器,在训练时冻结视觉编码器并微调语言编码器,实现快速稳定的预训练。
💻 使用示例
基础用法
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 = ["一只猫", "一只狗",'两只猫', '两只老虎','一只老虎'] # 这里是输入文本的,可以随意替换。
# 加载Taiyi 中文 text encoder
text_tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Taiyi-CLIP-RoBERTa-326M-ViT-H-Chinese")
text_encoder = BertModel.from_pretrained("IDEA-CCNL/Taiyi-CLIP-RoBERTa-326M-ViT-H-Chinese").eval()
url = "http://images.cocodataset.org/val2017/000000039769.jpg" # 这里可以换成任意图片的url
# 加载openclip的image encoder
clip_model, _, processor = open_clip.create_model_and_transforms('ViT-H-14', pretrained='laion2b_s32b_b79k')
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是尺度系数
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))
📚 详细文档
我们遵循CLIP的实验设置,以获得强大的视觉 - 语言表征。在训练中文版的CLIP时,我们使用chinese-roberta-wwm-large作为语言的编码器,并将open_clip中的ViT-H-14应用于视觉的编码器。为了快速且稳定地进行预训练,我们冻结了视觉编码器并且只微调语言编码器。
📄 许可证
本项目采用Apache-2.0许可证。
📖 引用
如果您在您的工作中使用了我们的模型,可以引用我们的论文:
@article{fengshenbang,
author = {Jiaxing Zhang and Ruyi Gan and Junjie Wang and Yuxiang Zhang and Lin Zhang and Ping Yang and Xinyu Gao and Ziwei Wu and Xiaoqun Dong and Junqing He and Jianheng Zhuo and Qi Yang and Yongfeng Huang and Xiayu Li and Yanghan Wu and Junyu Lu and Xinyu Zhu and Weifeng Chen and Ting Han and Kunhao Pan and Rui Wang and Hao Wang and Xiaojun Wu and Zhongshen Zeng and Chongpei Chen},
title = {Fengshenbang 1.0: Being the Foundation of Chinese Cognitive Intelligence},
journal = {CoRR},
volume = {abs/2209.02970},
year = {2022}
}
也可以引用我们的网站:
@misc{Fengshenbang-LM,
title={Fengshenbang-LM},
author={IDEA-CCNL},
year={2021},
howpublished={\url{https://github.com/IDEA-CCNL/Fengshenbang-LM}},
}