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-bestpool-oracle模型卡片
本仓库包含使用改进版OpenCLIP代码在TiC-DataComp-Yearly数据集(xlarge规模,bestpool筛选)上训练的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-bestpool-oracle"
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-bestpool-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}
}