🚀 TinyCLIP:通過親和度模仿和權重繼承進行CLIP蒸餾
TinyCLIP是一種用於大規模語言 - 圖像預訓練模型的新型跨模態蒸餾方法。該方法引入了親和度模仿和權重繼承兩項核心技術,挖掘了小型CLIP模型的潛力,充分利用大規模模型以及預訓練數據,在速度和準確性之間取得了最佳平衡。
🚀 快速開始
使用Transformers庫
以下是使用TinyCLIP進行零樣本圖像分類的示例代碼:
from PIL import Image
import requests
from transformers import CLIPModel, CLIPProcessor
model = CLIPModel.from_pretrained("wkcn/TinyCLIP-ViT-61M-32-Text-29M-LAION400M")
processor = CLIPProcessor.from_pretrained("wkcn/TinyCLIP-ViT-61M-32-Text-29M-LAION400M")
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%。
📚 詳細文檔
模型庫
模型 |
權重繼承方式 |
預訓練數據 |
ImageNet-1K Top-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 |
模型 |
注意:具有自動繼承功能的模型配置是自動生成的。
官方PyTorch實現
該項目的官方PyTorch實現代碼請參考:https://github.com/microsoft/Cream/tree/main/TinyCLIP
📄 許可證
本項目遵循的許可證請參考:License
📖 引用
如果本倉庫對你有幫助,請考慮引用它,感謝!
@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實現。感謝這些項目的貢獻者們的傑出貢獻!