🚀 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}
}