🚀 CLIP4Clip/WebVid - 150k模型卡片
CLIP4Clip/WebVid - 150k是一个视频 - 文本检索模型,它基于CLIP架构,在WebVid数据集的子集上进行训练,能够有效处理文本和视频数据,为大规模视频 - 文本检索应用提供支持。
🚀 快速开始
CLIP4Clip/WebVid - 150k是一个在WebVid数据集子集上训练的视频 - 文本检索模型。模型及训练方法在Lou等人的论文"Clip4Clip: An Empirical Study of CLIP for End to End Video Clip Retrieval"中有详细描述,并在配套的GitHub仓库中实现。
✨ 主要特性
- 基于CLIP架构:该模型基于[clip - vit - base - patch32](https://huggingface.co/openai/clip - vit - base - patch32)架构,借助CLIP的强大能力进行视频 - 文本检索。
- 使用WebVid数据集:训练过程使用了[WebVid数据集](https://m - bain.github.io/webvid - dataset/),该数据集包含大量来自网络的短视频及对应文本描述,本模型使用了其中前150,000个视频 - 文本对进行训练。
- 适用于大规模应用:可用于大规模视频 - 文本检索应用,如在约150万个视频的集合上进行搜索演示。
📦 安装指南
文档未提及具体安装步骤,故跳过此章节。
💻 使用示例
基础用法
import numpy as np
import torch
from transformers import CLIPTokenizer, CLIPTextModelWithProjection
search_sentence = "a basketball player performing a slam dunk"
model = CLIPTextModelWithProjection.from_pretrained("Searchium - ai/clip4clip - webvid150k")
tokenizer = CLIPTokenizer.from_pretrained("Searchium - ai/clip4clip - webvid150k")
inputs = tokenizer(text = search_sentence, return_tensors = "pt")
outputs = model(input_ids = inputs["input_ids"], attention_mask = inputs["attention_mask"])
final_output = outputs[0] / outputs[0].norm(dim = -1, keepdim = True)
final_output = final_output.cpu().detach().numpy()
print("final output: ", final_output)
高级用法
若要提取视频嵌入向量,可参考额外的笔记本["GSI_VideoRetrieval_VideoEmbedding.ipynb"](https://huggingface.co/Searchium - ai/clip4clip - webvid150k/blob/main/Notebooks/GSI_VideoRetrieval_VideoEmbedding.ipynb),其中提供了提取视频嵌入向量的说明及预处理视频所需的工具。
📚 详细文档
模型预期用途
此模型旨在用于大规模视频 - 文本检索应用。可参考配套的[视频搜索空间](https://huggingface.co/spaces/Searchium - ai/Video - Search),该空间在约150万个视频的大规模集合上提供了搜索演示,展示了模型基于文本查询有效检索视频的能力。
动机
原作者的主要动机是利用CLIP图像 - 语言预训练模型的能力,将其应用于从视频中学习视觉 - 时间概念,从而改进基于视频的搜索。借助WebVid数据集的大规模和多样性,模型的能力得到了进一步提升。
评估
为评估模型性能,使用了Webvid数据集中最后10,000个视频片段及其伴随文本。评估指标包括R1、R5、R10、MedianR和MeanR,评估对象如下:
- 零样本预训练的clip - vit - base - patch32模型
- 基于CLIP4Clip在数据集[MSR - VTT](https://paperswithcode.com/dataset/msr - vtt)(包含10,000个视频 - 文本对)上训练的权重
- 基于CLIP4Clip在Webvid - 2M数据集的150K子集上训练的权重
- 基于CLIP4Clip在Webvid - 2M数据集的150K子集上训练的权重,经过二值化处理并在100个顶级搜索上进一步微调,以加速和提高搜索效率[1]。
模型 |
R1 ↑ |
R5 ↑ |
R10 ↑ |
MedianR ↓ |
MeanR ↓ |
零样本clip权重 |
37.16 |
62.10 |
71.16 |
3.0 |
42.2128 |
基于MSR - VTT训练的CLIP4Clip权重 |
38.38 |
62.89 |
72.01 |
3.0 |
39.3023 |
基于150k Webvid训练的CLIP4Clip |
50.74 |
77.30 |
85.05 |
1.0 |
14.9535 |
经过二值化和重排100处理的基于150k Webvid训练的CLIP4Clip |
50.56 |
76.39 |
83.51 |
1.0 |
43.2964 |
有关评估的详细描述,请参考笔记本[GSI_VideoRetrieval - Evaluation](https://huggingface.co/Searchium - ai/clip4clip - webvid150k/blob/main/Notebooks/GSI_VideoRetrieval - Evaluation.ipynb)。
致谢
感谢Searchium的Diana Mazenko将模型适配并加载到Hugging Face,以及创建了用于大规模视频搜索演示的Hugging Face [SPACE](https://huggingface.co/spaces/Searchium - ai/Video - Search)。
同时感谢Lou等人在CLIP4Clip方面的全面工作以及公开可用的代码。
引用
CLIP4Clip论文
@Article{Luo2021CLIP4Clip,
author = {Huaishao Luo and Lei Ji and Ming Zhong and Yang Chen and Wen Lei and Nan Duan and Tianrui Li},
title = {{CLIP4Clip}: An Empirical Study of CLIP for End to End Video Clip Retrieval},
journal = {arXiv preprint arXiv:2104.08860},
year = {2021},
}
OpenAI CLIP论文
@inproceedings{Radford2021LearningTV,
title={Learning Transferable Visual Models From Natural Language Supervision},
author={Alec Radford and Jong Wook Kim and Chris Hallacy and A. Ramesh and Gabriel Goh and Sandhini Agarwal and Girish Sastry and Amanda Askell and Pamela Mishkin and Jack Clark and Gretchen Krueger and Ilya Sutskever},
booktitle={ICML},
year={2021}
}