🚀 太乙-CLIP-Roberta-102M-中文
太乙-CLIP-Roberta-102M-中文是首個開源的中文CLIP模型,在1.23億圖文對上進行預訓練,文本端採用RoBERTa-base,能有效獲取強大的視覺 - 語言表徵。
🚀 快速開始
太乙-CLIP-Roberta-102M-中文模型可用於圖像特徵提取等多模態任務。你可以通過以下步驟快速使用該模型。
✨ 主要特性
- 首個開源中文CLIP:填補了Huggingface社區中開源中文CLIP的空白。
- 強大的視覺 - 語言表徵:遵循CLIP實驗設置,在大量圖文數據上預訓練。
- 高效訓練策略:凍結視覺編碼器,只微調語言編碼器,訓練快速且穩定。
📦 安裝指南
文檔未提及安裝步驟,暫不提供。
💻 使用示例
基礎用法
from PIL import Image
import requests
import clip
import torch
from transformers import BertForSequenceClassification, 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-102M-Chinese")
text_encoder = BertForSequenceClassification.from_pretrained("IDEA-CCNL/Taiyi-CLIP-Roberta-102M-Chinese").eval()
text = text_tokenizer(query_texts, return_tensors='pt', padding=True)['input_ids']
url = "http://images.cocodataset.org/val2017/000000039769.jpg" # 這裡可以換成任意圖片的url
# 加載CLIP的image encoder
clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
image = processor(images=Image.open(requests.get(url, stream=True).raw), return_tensors="pt")
with torch.no_grad():
image_features = clip_model.get_image_features(**image)
text_features = text_encoder(text).logits
# 歸一化
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 (Roberta) |
參數 |
102M |
額外 |
中文 |
模型信息
我們遵循CLIP的實驗設置,以獲得強大的視覺 - 語言表徵。在訓練中文版的CLIP時,我們使用chinese-roberta-wwm作為語言的編碼器,並將CLIP中的ViT - B - 32應用於視覺的編碼器。為了快速且穩定地進行預訓練,我們凍結了視覺編碼器並且只微調語言編碼器。此外,我們將Noah - Wukong數據集(100M)和Zero數據集(23M)用作預訓練的數據集,訓練了24個epoch,在A100x32上訓練了7天。據我們所知,我們的Taiyi - CLIP是目前Huggingface社區中首個的開源中文CLIP。
下游效果
零樣本分類
模型 |
數據集 |
Top1 |
Top5 |
Taiyi - CLIP - Roberta - 102M - 中文 |
ImageNet1k - CN |
42.85% |
71.48% |
零樣本文本到圖像檢索
模型 |
數據集 |
Top1 |
Top5 |
Top10 |
Taiyi - CLIP - Roberta - 102M - 中文 |
Flickr30k - CNA - test |
46.32% |
74.58% |
83.44% |
Taiyi - CLIP - Roberta - 102M - 中文 |
COCO - CN - test |
47.10% |
78.53% |
87.84% |
Taiyi - CLIP - Roberta - 102M - 中文 |
wukong50k |
49.18% |
81.94% |
90.27% |
🔧 技術細節
文檔未提及足夠詳細的技術實現細節,暫不提供。
📄 許可證
本項目採用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}},
}