🚀 TinyCLIP:通过亲和度模仿和权重继承实现CLIP蒸馏
TinyCLIP 是一种针对大规模语言 - 图像预训练模型的新型 跨模态蒸馏 方法。该方法引入了两项核心技术:亲和度模仿 和 权重继承。这项工作释放了小型CLIP模型的潜力,充分利用大规模模型以及预训练数据,在速度和准确性之间取得了最佳平衡。
🚀 快速开始
使用Transformers库调用模型
from PIL import Image
import requests
from transformers import CLIPProcessor, CLIPModel
model = CLIPModel.from_pretrained("wkcn/TinyCLIP-ViT-8M-16-Text-3M-YFCC15M")
processor = CLIPProcessor.from_pretrained("wkcn/TinyCLIP-ViT-8M-16-Text-3M-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% 的准确率。
📚 详细文档
模型库
模型 |
权重继承方式 |
预训练数据 |
ImageNet-1K 准确率@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实现
点击查看
引用
如果本仓库对你有帮助,请考虑引用它。非常感谢!
@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。感谢贡献者们的杰出贡献!
📄 许可证