🚀 TinyCLIP:通過親和度模仿和權重繼承實現CLIP蒸餾
TinyCLIP 是一種用於大規模語言 - 圖像預訓練模型的新型 跨模態蒸餾 方法。該方法引入了兩項核心技術:親和度模仿 和 權重繼承。這項工作挖掘了小型CLIP模型的潛力,充分利用了大規模模型以及預訓練數據,在速度和準確性之間取得了最佳平衡。
🚀 快速開始
使用Transformers庫
from PIL import Image
import requests
from transformers import CLIPProcessor, CLIPModel
model = CLIPModel.from_pretrained("wkcn/TinyCLIP-ViT-40M-32-Text-19M-LAION400M")
processor = CLIPProcessor.from_pretrained("wkcn/TinyCLIP-ViT-40M-32-Text-19M-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準確率(%) |
乘加運算次數(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實現
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。感謝貢獻者們的傑出貢獻!
📄 許可證