VideoLLaMA2

VideoLLaMA2

增强视频理解的多模态语言模型

VideoLLaMA2是一款先进的视频语言模型,通过增强空间-时间建模和音频理解能力,提高了视频问答和描述任务的性能。该模型在零样本视频问答等多项基准测试中表现出色。VideoLLaMA2能处理长视频序列并理解复杂视听内容,为视频理解技术带来新进展。

VideoLLaMA2视频理解大语言模型多模态AIGithub开源项目
<p align="center"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/efd17735-0e5d-4732-bb4f-d00629e3a21f.png" width="150" style="margin-bottom: 0.2;"/> <p> <h3 align="center"><a href="https://arxiv.org/abs/2406.07476" style="color:#9C276A"> VideoLLaMA 2:提升视频-大语言模型中的时空建模和音频理解能力</a></h3> <h5 align="center"> 如果我们的项目对您有帮助,请在GitHub上给我们一个星标⭐来支持我们。🙏🙏 </h2> <h5 align="center">

hf_space hf_checkpoint hf_data arXiv <br> License Hits GitHub issues GitHub closed issues <br>

</h5>

PWC <br> PWC <br> PWC <br> PWC <br> PWC <br>

<details open><summary>💡 我们团队的一些其他多模态大语言模型项目可能会引起您的兴趣 ✨。 </summary><p> <!-- may -->

Video-LLaMA:一个用于视频理解的指令调优音视频语言模型 <br> 张航, 李鑫, 冰立冬 <br> github github arXiv <br>

VCD:通过视觉对比解码缓解大型视觉语言模型中的物体幻觉 <br> 冷思聪, 张航, 陈冠政, 李鑫, 卢仕健, 缪春燕, 冰立冬 <br> github github arXiv <br>

</p></details> <div align="center"><video src="https://github.com/DAMO-NLP-SG/VideoLLaMA2/assets/18526640/e0e7951c-f392-42ed-afad-b2c7984d3e38" width="800"></div> ## 📰 新闻 * **[2024.07.30]** 发布 [VideoLLaMA2-8x7B-Base](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-8x7B-Base) 和 [VideoLLaMA2-8x7B](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-8x7B) 的检查点。 * **[2024.06.25]** 🔥🔥 截至6月25日,我们的 [VideoLLaMA2-7B-16F](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-7B-16F) 在 [MLVU 排行榜](https://github.com/JUNJIE99/MLVU?tab=readme-ov-file#trophy-mini-leaderboard) 上是**排名第一**的约7B规模的VideoLLM。 * **[2024.06.18]** 🔥🔥 截至6月18日,我们的 [VideoLLaMA2-7B-16F](https://huggingface.co/DAMO-NLP-SG/VideoLLaMA2-7B-16F) 在 [VideoMME 排行榜](https://video-mme.github.io/home_page.html#leaderboard) 上是**排名第一**的约7B规模的VideoLLM。 * **[2024.06.17]** 👋👋 更新技术报告,包含最新结果和之前遗漏的参考文献。如果您有与VideoLLaMA 2密切相关但未在论文中提及的工作,欢迎告知我们。 * **[2024.06.14]** 🔥🔥 [在线演示](https://huggingface.co/spaces/lixin4ever/VideoLLaMA2) 已可用。 * **[2024.06.03]** 发布VideoLLaMA 2的训练、评估和服务代码。 <img src="https://github.com/DAMO-NLP-SG/VideoLLaMA2/assets/18526640/b9faf24f-bdd2-4728-9385-acea17ea086d" width="800" />

🛠️ 要求和安装

基本依赖:

  • Python >= 3.8
  • Pytorch >= 2.2.0
  • CUDA版本 >= 11.8
  • transformers >= 4.41.2 (用于mistral分词器)
  • tokenizers >= 0.19.1 (用于mistral分词器)

[在线模式] 安装所需包(更适合开发):

git clone https://github.com/DAMO-NLP-SG/VideoLLaMA2 cd VideoLLaMA2 pip install -r requirements.txt pip install flash-attn==2.5.8 --no-build-isolation

[离线模式] 将VideoLLaMA2作为Python包安装(更适合直接使用):

git clone https://github.com/DAMO-NLP-SG/VideoLLaMA2 cd VideoLLaMA2 pip install --upgrade pip # 启用PEP 660支持 pip install -e . pip install flash-attn==2.5.8 --no-build-isolation

🚀 主要结果

多选视频问答和视频描述

<p><img src="https://github.com/user-attachments/assets/fbe3e3c2-b0f1-4e29-8b92-bc3611192909" width="800" "/></p>

开放式视频问答

<p><img src="https://github.com/user-attachments/assets/cee2efe1-309e-4301-a217-e2a848799953" width="800" "/></p>

:earth_americas: 模型库

模型名称模型类型视觉编码器语言解码器训练帧数
VideoLLaMA2-7B-Base基础clip-vit-large-patch14-336Mistral-7B-Instruct-v0.28
VideoLLaMA2-7B对话clip-vit-large-patch14-336Mistral-7B-Instruct-v0.28
VideoLLaMA2-7B-16F-Base基础clip-vit-large-patch14-336Mistral-7B-Instruct-v0.216
VideoLLaMA2-7B-16F对话clip-vit-large-patch14-336Mistral-7B-Instruct-v0.216
VideoLLaMA2-8x7B-Base基础clip-vit-large-patch14-336Mixtral-8x7B-Instruct-v0.18
VideoLLaMA2-8x7B对话clip-vit-large-patch14-336Mixtral-8x7B-Instruct-v0.18
VideoLLaMA2-72B-Base基础clip-vit-large-patch14-336Qwen2-72B-Instruct8
VideoLLaMA2-72B对话clip-vit-large-patch14-336Qwen2-72B-Instruct8

🤗 演示

强烈建议先试用我们的在线演示

要在您的设备上运行基于视频的LLM(大型语言模型)网页演示,首先需要确保您已准备好必要的模型检查点,然后按照概述的步骤成功启动演示。

单模型版本

python videollama2/serve/gradio_web_server_adhoc.py

多模型版本

  1. 启动全局控制器
cd /path/to/VideoLLaMA2 python -m videollama2.serve.controller --host 0.0.0.0 --port 10000
  1. 启动gradio网页服务器
python -m videollama2.serve.gradio_web_server --controller http://localhost:10000 --model-list-mode reload
  1. 启动一个或多个模型工作器
# export HF_ENDPOINT=https://hf-mirror.com # 如果您无法访问 Hugging Face,请尝试取消注释此行。 python -m videollama2.serve.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40000 --worker http://localhost:40000 --model-path /PATH/TO/MODEL1 python -m videollama2.serve.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40001 --worker http://localhost:40001 --model-path /PATH/TO/MODEL2 python -m videollama2.serve.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40002 --worker http://localhost:40002 --model-path /PATH/TO/MODEL3 ...

🗝️ 训练和评估

快速入门

为了方便在我们的代码基础上进行进一步开发,我们提供了一个快速入门指南,介绍如何使用VideoLLaVA数据集训练定制的VideoLLaMA2,并在主流视频-语言模型基准上评估训练后的模型。

  1. 训练数据结构:
VideoLLaMA2 ├── datasets │ ├── videollava_pt | | ├── llava_image/ # 可在以下链接获取:https://pan.baidu.com/s/17GYcE69FcJjjUM0e4Gad2w?pwd=9ga3 或 https://drive.google.com/drive/folders/1QmFj2FcMAoWNCUyiUtdcW0-IOhLbOBcf?usp=drive_link | | ├── valley/ # 可在以下链接获取:https://pan.baidu.com/s/1jluOimE7mmihEBfnpwwCew?pwd=jyjz 或 https://drive.google.com/drive/folders/1QmFj2FcMAoWNCUyiUtdcW0-IOhLbOBcf?usp=drive_link | | └── valley_llavaimage.json # 可在以下链接获取:https://drive.google.com/file/d/1zGRyVSUMoczGq6cjQFmT0prH67bu2wXD/view,包含703K视频-文本对和558K图像-文本对 │ ├── videollava_sft | | ├── llava_image_tune/ # 可在以下链接获取:https://pan.baidu.com/s/1l-jT6t_DlN5DTklwArsqGw?pwd=o6ko | | ├── videochatgpt_tune/ # 可在以下链接获取:https://pan.baidu.com/s/10hJ_U7wVmYTUo75YHc_n8g?pwd=g1hf | | └── videochatgpt_llavaimage_tune.json # 可在以下链接获取:https://drive.google.com/file/d/1zGRyVSUMoczGq6cjQFmT0prH67bu2wXD/view,包含100K以视频为中心、625K以图像为中心和40K纯文本对话
  1. 命令:
# VideoLLaMA2-vllava 预训练 bash scripts/vllava/pretrain.sh # VideoLLaMA2-vllava 微调 bash scripts/vllava/finetune.sh
  1. 评估数据结构:
VideoLLaMA2 ├── eval │ ├── egoschema # 官方网站:https://github.com/egoschema/EgoSchema | | ├── good_clips_git/ # 可在以下链接获取:https://drive.google.com/drive/folders/1SS0VVz8rML1e5gWq7D7VtP1oxE2UtmhQ | | └── questions.json # 可在以下链接获取:https://github.com/egoschema/EgoSchema/blob/main/questions.json │ ├── mvbench # 官方网站:https://huggingface.co/datasets/OpenGVLab/MVBench | | ├── video/ | | | ├── clever/ | | | └── ... | | └── json/ | | | ├── action_antonym.json | | | └── ... │ ├── perception_test_mcqa # 官方网站:https://huggingface.co/datasets/OpenGVLab/MVBench | | ├── videos/ # 可在以下链接获取:https://storage.googleapis.com/dm-perception-test/zip_data/test_videos.zip | | └── mc_question_test.json # 从以下链接下载:https://storage.googleapis.com/dm-perception-test/zip_data/mc_question_test_annotations.zip │ ├── videomme # 官方网站:https://video-mme.github.io/home_page.html#leaderboard | | ├── test-00000-of-00001.parquet | | ├── videos/ | | └── subtitles/ │ ├── Activitynet_Zero_Shot_QA # 官方网站:https://github.com/MILVLG/activitynet-qa | | ├── all_test/ # 可在以下链接获取:https://mbzuaiac-my.sharepoint.com/:u:/g/personal/hanoona_bangalath_mbzuai_ac_ae/EatOpE7j68tLm2XAd0u6b8ABGGdVAwLMN6rqlDGM_DwhVA?e=90WIuW | | ├── test_q.json # 可在以下链接获取:https://github.com/MILVLG/activitynet-qa/tree/master/dataset | | └── test_a.json # 可在以下链接获取:https://github.com/MILVLG/activitynet-qa/tree/master/dataset │ ├── MSVD_Zero_Shot_QA # 官方网站:https://github.com/xudejing/video-question-answering | | ├── videos/ | | ├── test_q.json | | └── test_a.json │ ├── videochatgpt_gen # 官方网站:https://github.com/mbzuai-oryx/Video-ChatGPT/tree/main/quantitative_evaluation | | ├── Test_Videos/ # 可在以下链接获取:https://mbzuaiac-my.sharepoint.com/:u:/g/personal/hanoona_bangalath_mbzuai_ac_ae/EatOpE7j68tLm2XAd0u6b8ABGGdVAwLMN6rqlDGM_DwhVA?e=90WIuW | | ├── Test_Human_Annotated_Captions/ # 可在以下链接获取:https://mbzuaiac-my.sharepoint.com/personal/hanoona_bangalath_mbzuai_ac_ae/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Fhanoona%5Fbangalath%5Fmbzuai%5Fac%5Fae%2FDocuments%2FVideo%2DChatGPT%2FData%5FCode%5FModel%5FRelease%2FQuantitative%5FEvaluation%2Fbenchamarking%2FTest%5FHuman%5FAnnotated%5FCaptions%2Ezip&parent=%2Fpersonal%2Fhanoona%5Fbangalath%5Fmbzuai%5Fac%5Fae%2FDocuments%2FVideo%2DChatGPT%2FData%5FCode%5FModel%5FRelease%2FQuantitative%5FEvaluation%2Fbenchamarking&ga=1 | | ├── generic_qa.json # 这三个json文件可在以下链接获取:https://mbzuaiac-my.sharepoint.com/personal/hanoona_bangalath_mbzuai_ac_ae/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Fhanoona%5Fbangalath%5Fmbzuai%5Fac%5Fae%2FDocuments%2FVideo%2DChatGPT%2FData%5FCode%5FModel%5FRelease%2FQuantitative%5FEvaluation%2Fbenchamarking%2FBenchmarking%5FQA&ga=1 | | ├── temporal_qa.json | | └── consistency_qa.json
  1. 命令:
# mvbench 评估 CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_video_qa_mvbench.sh # activitynet-qa 评估(需要设置azure openai key/endpoint/deployname) CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_video_qa_mvbench.sh

数据格式

如果您想在自己的数据上训练视频-语言模型,您需要按照以下步骤准备视频/图像微调数据:

  1. 假设你的数据结构如下:
VideoLLaMA2 ├── datasets │ ├── custom_sft | ├── images | ├── videos | | └── custom.json
  1. 然后你应该按照以下格式重新组织标注的视频/图像 sft 数据:
[ { "id": 0, "video": "images/xxx.jpg", "conversations": [ { "from": "human", "value": "<image>\n图像中巴士的颜色是什么?" }, { "from": "gpt", "value": "图像中的巴士是白色和红色的。" }, ... ], } { "id": 1, "video": "videos/xxx.mp4", "conversations": [ { "from": "human", "value": "<video>\n视频中主要发生了哪些活动?" }, { "from": "gpt", "value": "视频中主要发生的活动包括一个男人准备摄影设备,一群男人乘坐直升机,以及一个男人驾驶船在水中航行。" }, ... ], }, ... ]
  1. 修改 scripts/custom/finetune.sh
... --data_path datasets/custom_sft/custom.json --data_folder datasets/custom_sft/ --pretrain_mm_mlp_adapter CONNECTOR_DOWNLOAD_PATH (例如:DAMO-NLP-SG/VideoLLaMA2-7B-Base) ...

🤖 推理

视频/图像推理:

import sys sys.path.append('./') from videollama2 import model_init, mm_infer from videollama2.utils import disable_torch_init def inference(): disable_torch_init() # 视频推理 modal = 'video' modal_path = 'assets/cat_and_chicken.mp4' instruct = '视频中有哪些动物,它们在做什么,视频给人什么感觉?' # 回复: # 视频中有一只小猫和一只小鸡在一起玩耍。小猫躺在地板上,而小鸡在它周围跳来跳去。两只动物之间有互动和玩耍的行为,视频给人一种可爱和温馨的感觉。 # 图像推理 modal = 'image' modal_path = 'assets/sora.png' instruct = '这个女人穿着什么,在做什么,图片给人什么感觉?' # 回复: # 图片中的女人穿着黑色外套和墨镜,正在雨后的城市街道上行走。这张图片给人一种充满活力和生机的感觉,明亮的城市灯光反射在湿漉漉的人行道上,营造出一种视觉上富有吸引力的氛围。女人的存在为场景增添了一种时尚感和自信感,她正在繁华的都市环境中从容前行。 model_path = 'DAMO-NLP-SG/VideoLLaMA2-7B' # 基础模型推理(只需替换 model_path) # model_path = 'DAMO-NLP-SG/VideoLLaMA2-7B-Base' model, processor, tokenizer = model_init(model_path) output = mm_infer(processor[modal](modal_path), instruct, model=model, tokenizer=tokenizer, do_sample=False, modal=modal) print(output) if __name__ == "__main__": inference()

📑 引用

如果您发现 VideoLLaMA 对您的研究和应用有用,请使用以下 BibTeX 进行引用:

@article{damonlpsg2024videollama2, title={VideoLLaMA 2: Advancing Spatial-Temporal Modeling and Audio Understanding in Video-LLMs}, author={Cheng, Zesen and Leng, Sicong and Zhang, Hang and Xin, Yifei and Li, Xin and Chen, Guanzheng and Zhu, Yongxin and Zhang, Wenqi and Luo, Ziyang and Zhao, Deli and Bing, Lidong}, journal={arXiv preprint arXiv:2406.07476}, year={2024}, url = {https://arxiv.org/abs/2406.07476} } @article{damonlpsg2023videollama, title = {Video-LLaMA: An Instruction-tuned Audio-Visual Language Model for Video Understanding}, author = {Zhang, Hang and Li, Xin and Bing, Lidong}, journal = {arXiv preprint arXiv:2306.02858}, year = {2023}, url = {https://arxiv.org/abs/2306.02858} }

👍 致谢

VideoLLaMA 2 的代码库改编自 LLaVA 1.5FastChat。我们还感谢以下项目,VideoLLaMA 2 由此而生:

🔒 许可证

本项目基于 Apache 2.0 许可证发布,详见 LICENSE 文件。 该服务是一个仅供非商业用途的研究预览版,受 LLaMA 和 Mistral 的模型许可、OpenAI 生成数据的使用条款以及 ShareGPT 的隐私惯例的约束。如果您发现任何潜在的违规行为,请与我们联系。

编辑推荐精选

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成AI工具AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机AI图像热门
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

下拉加载更多