🚀 TinyCLIP:通過親和度模仿和權重繼承實現CLIP蒸餾
TinyCLIP是一種用於大規模語言 - 圖像預訓練模型的新型跨模態蒸餾方法。該方法引入了兩項核心技術:親和度模仿和權重繼承。這項工作釋放了小型CLIP模型的潛力,充分利用了大規模模型以及預訓練數據,在速度和準確性之間取得了最佳平衡。
🚀 快速開始
與Transformers庫配合使用
from PIL import Image
import requests
from transformers import CLIPProcessor, CLIPModel
model = CLIPModel.from_pretrained("wkcn/TinyCLIP-ViT-39M-16-Text-19M-YFCC15M")
processor = CLIPProcessor.from_pretrained("wkcn/TinyCLIP-ViT-39M-16-Text-19M-YFCC15M")
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True)
outputs = model(**inputs)
logits_per_image = outputs.logits_per_image
probs = logits_per_image.softmax(dim=1)
✨ 主要特性
特性亮點
- TinyCLIP ViT - 45M/32僅使用ViT - B/32一半的參數,就能實現相當的零樣本性能。
- TinyCLIP ResNet - 19M在參數減少50%的同時,推理速度提升了2倍,並在ImageNet上獲得了56.4%的準確率。
模型庫
屬性 |
詳情 |
模型類型 |
TinyCLIP系列模型,包括不同參數規模和架構(如ViT、ResNet)的變體 |
訓練數據 |
YFCC - 15M、LAION - 400M、LAION+YFCC - 400M |
模型 |
權重繼承方式 |
預訓練數據 |
ImageNet-1K 準確率@1(%) |
MACs(G) |
吞吐量(對/秒) |
鏈接 |
TinyCLIP ViT-39M/16 Text-19M |
手動 |
YFCC-15M |
63.5 |
9.5 |
1,469 |
模型 |
TinyCLIP ViT-8M/16 Text-3M |
手動 |
YFCC-15M |
41.1 |
2.0 |
4,150 |
模型 |
TinyCLIP ResNet-30M Text-29M |
手動 |
LAION-400M |
59.1 |
6.9 |
1,811 |
模型 |
TinyCLIP ResNet-19M Text-19M |
手動 |
LAION-400M |
56.4 |
4.4 |
3,024 |
模型 |
TinyCLIP ViT-61M/32 Text-29M |
手動 |
LAION-400M |
62.4 |
5.3 |
3,191 |
模型 |
TinyCLIP ViT-40M/32 Text-19M |
手動 |
LAION-400M |
59.8 |
3.5 |
4,641 |
模型 |
TinyCLIP ViT-63M/32 Text-31M |
自動 |
LAION-400M |
63.9 |
5.6 |
2,905 |
模型 |
TinyCLIP ViT-45M/32 Text-18M |
自動 |
LAION-400M |
61.4 |
3.7 |
3,682 |
模型 |
TinyCLIP ViT-22M/32 Text-10M |
自動 |
LAION-400M |
53.7 |
1.9 |
5,504 |
模型 |
TinyCLIP ViT-63M/32 Text-31M |
自動 |
LAION+YFCC-400M |
64.5 |
5.6 |
2,909 |
模型 |
TinyCLIP ViT-45M/32 Text-18M |
自動 |
LAION+YFCC-400M |
62.7 |
1.9 |
3,685 |
模型 |
注:具有自動繼承的模型配置是自動生成的。
💻 使用示例
基礎用法
from PIL import Image
import requests
from transformers import CLIPProcessor, CLIPModel
model = CLIPModel.from_pretrained("wkcn/TinyCLIP-ViT-39M-16-Text-19M-YFCC15M")
processor = CLIPProcessor.from_pretrained("wkcn/TinyCLIP-ViT-39M-16-Text-19M-YFCC15M")
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True)
outputs = model(**inputs)
logits_per_image = outputs.logits_per_image
probs = logits_per_image.softmax(dim=1)
📚 詳細文檔
官方PyTorch實現
https://github.com/microsoft/Cream/tree/main/TinyCLIP
引用
如果這個倉庫對你有幫助,請考慮引用它。非常感謝!
@InProceedings{tinyclip,
title = {TinyCLIP: CLIP Distillation via Affinity Mimicking and Weight Inheritance},
author = {Wu, Kan and Peng, Houwen and Zhou, Zhenghong and Xiao, Bin and Liu, Mengchen and Yuan, Lu and Xuan, Hong and Valenzuela, Michael and Chen, Xi (Stephen) and Wang, Xinggang and Chao, Hongyang and Hu, Han},
booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
month = {October},
year = {2023},
pages = {21970-21980}
}
致謝
我們的代碼基於CLIP、OpenCLIP、CoFi和PyTorch。感謝貢獻者們的傑出貢獻!
📄 許可證