🚀 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实现。感谢这些项目的贡献者们的杰出贡献!