license: other
license_name: custom-apple-license
license_link: https://github.com/apple/ml-tic-clip/blob/main/LICENSE
tags:
- 视觉
- 零样本图像分类
datasets:
- apple/TiC-DataComp
library_name: tic-clip
TiC-CLIP基础累积模型卡
本仓库包含使用我们改进的OpenCLIP代码,在TiC-DataComp-Yearly(xlarge规模,基础过滤)数据集上训练的TiC-CLIP模型,数据涵盖2014至2022年。
更多信息请参阅我们的GitHub仓库。
模型详情
模型描述
保持大型基础模型与最新数据同步本质上成本高昂。为避免频繁重新训练带来的巨额开销,持续训练这些模型势在必行。这一问题因缺乏大规模持续学习基准或基线而进一步加剧。我们首次提出了用于训练视觉语言模型的时间持续(TiC)基准:TiC-DataComp、TiC-YFCC和TiC-Redcaps。其中TiC-DataComp作为最大数据集,包含跨越9年(2014-2022)的127亿条带时间戳的图文对。我们首先利用这些基准设计动态评估方案,衡量现有模型的时间鲁棒性。研究表明,OpenAI的CLIP(基于2020年前数据训练)在我们构建的2021-2022年检索任务上,零样本准确率较OpenCLIP库中新近训练的模型下降约8%。随后我们探索如何高效训练时序连续数据上的模型。实验证明,采用简单的基于回放的持续训练策略(从最后检查点继续训练并重放旧数据),相比传统从头训练方法可减少2.5倍计算量。代码详见此链接。
模型来源[可选]
用途
研究人员可利用TiC-CLIP预训练模型加速持续学习方法的开发,即从预训练检查点出发,在后续年份/月份数据上持续训练。
快速开始
本模型兼容DataComp评估套件及我们为TiC-DataComp-Retrieval和TiC-DataCompNet评估定制的补丁版本。模型也可用于恢复训练或作为OpenCLIP代码新训练的初始化。创建评估集请遵循GitHub仓库说明,标准38数据集评估请参考DataComp。
以下代码片段假设已按GitHub指南准备好TiC-DataComp数据。
训练
YEAR=2016
REPO="apple/TiC-CLIP-basic-cumulative"
huggingface-cli下载 $REPO checkpoints/$YEAR.pt
pushd datacomp
final_data_dir=$TIC_DATACOMP_Y_PATH/train/$YEAR/
torchrun --nproc_per_node 8 --nnodes 1 \
train.py \
--scale "tic_medium" \
--dataset_resampled \
--data_dir $final_data_dir \
--output_dir "./results/" \
--exp_name "datacomp_medium-basic_cumulative" \
--imagenet_val $IMAGENET_VAL_PATH \
--save_frequency 1 \
--resume
popd
评估
pushd datacomp
python ../dataset_creation/tic-datacomp/generate_tasklist.py --yaml-path tasklist.yml --sample-eval --eval-tasks retrieval/yearly,datacompnet/yearly
python evaluate.py --data_dir data/ --train_output_dir ./results --use_model "ViT-B-16 $YEAR.pt" --skip_hf --skip_db --skip_notification
OpenCLIP加载与推理示例
import open_clip
from huggingface_hub import hf_hub_download
filename = hf_hub_download(repo_id="apple/TiC-CLIP-basic-cumulative", filename="checkpoints/2016.pt")
model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16', filename)
tokenizer = open_clip.get_tokenizer('ViT-B-16')
image = preprocess(Image.open("image.png").convert('RGB')).unsqueeze(0)
text = tokenizer(["示意图", "狗", "猫"])
with torch.no_grad(), torch.cuda.amp.autocast():
image_features = model.encode_image(image)
text_features = model.encode_text(text)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("标签概率:", text_probs)
训练详情
训练数据
详见TiC-DataComp。
训练流程
请参阅TiC-CLIP论文第2-3节。
引用
TiC-CLIP: CLIP模型的持续训练. (ICLR 2024)
Garg等.
@inproceedings{garg2024tic,
title={TiC-CLIP: Continual Training of CLIP Models},
author={Garg, Saurabh and Farajtabar, Mehrdad and Pouransari, Hadi and Vemulapalli, Raviteja and Mehta, Sachin and Tuzel, Oncel and Shankar, Vaishaal and Faghri, Fartash},
booktitle={The Twelfth International Conference on Learning Representations (ICLR)},
year={2024},
url={https://openreview.net/forum?id=TLADT8Wrhn}
}