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-basic-oracle模型卡
本仓库包含使用我们修改版OpenCLIP代码在TiC-DataComp-Yearly数据集(xlarge规模,基础过滤)上训练的TiC-CLIP模型,训练数据时间跨度为2014至2022年。更多信息请参阅我们的GitHub仓库。
模型详情
模型描述
保持大型基础模型与最新数据同步本质上成本高昂。为避免持续重训练带来的过高成本,必须对这些模型进行持续训练。由于缺乏大规模持续学习基准或基线,这一问题更加突出。我们首次提出用于训练视觉语言模型的时间持续(TiC)基准集:TiC-DataComp、TiC-YFCC和TiC-Redcaps。其中最大规模的TiC-DataComp包含超过127亿条带时间戳的图文对,时间跨度达9年(2014-2022年)。我们首先利用这些基准构建动态评估体系,衡量现有模型的时间鲁棒性。研究表明,OpenAI的CLIP模型(基于2020年前数据训练)在我们构建的2021-2022年检索任务上,其零样本准确率比OpenCLIP仓库中新近训练的模型下降约8%。随后我们研究如何高效训练时间连续数据上的模型。实验证明,采用简单的记忆回放方法——从最后检查点继续训练并重放旧数据——相比标准从头训练方法可减少2.5倍计算量。代码详见此链接。
模型来源[可选]
用途
研究人员可使用TiC-CLIP预训练模型加速持续学习方法的开发,即从预训练检查点出发,在后续年度/月份数据上持续训练。
快速开始
本模型兼容DataComp评估套件及我们修改版的DataComp,可用于TiC-DataComp-Retrieval和TiC-DataCompNet评估。也可通过OpenCLIP代码用于恢复训练或作为新训练的初始化。创建评估集请遵循GitHub仓库说明,标准38数据集评估请参考DataComp。
以下代码片段假设已按GitHub仓库说明准备好TiC-DataComp数据。
训练
YEAR=2016
REPO="apple/TiC-CLIP-basic-oracle"
huggingface-cli download $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-oracle", 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}
}