GitHub - DAMO-NLP-SG/VideoLLaMA2 at audio_visual (original) (raw)
VideoLLaMA 2: Advancing Spatial-Temporal Modeling and Audio Understanding in Video-LLMs
If our project helps you, please give us a star ⭐ on GitHub to support us. 🙏🙏
💡 Some other multimodal-LLM projects from our team may interest you ✨.
Video-LLaMA: An Instruction-tuned Audio-Visual Language Model for Video Understanding
Hang Zhang, Xin Li, Lidong Bing![]()
![]()
![]()
VCD: Mitigating Object Hallucinations in Large Vision-Language Models through Visual Contrastive Decoding
Sicong Leng, Hang Zhang, Guanzheng Chen, Xin Li, Shijian Lu, Chunyan Miao, Lidong Bing![]()
![]()
![]()
The Curse of Multi-Modalities: Evaluating Hallucinations of Large Multimodal Models across Language, Visual, and Audio
Sicong Leng, Yun Xing, Zesen Cheng, Yang Zhou, Hang Zhang, Xin Li, Deli Zhao, Shijian Lu, Chunyan Miao, Lidong Bing![]()
![]()
![]()
demo_video.webm
📰 News
- [2024.10.22] Release checkpoints of VideoLLaMA2.1-7B-AV.
- [2024.10.15] Release checkpoints of VideoLLaMA2.1-7B-16F-Base and VideoLLaMA2.1-7B-16F.
- [2024.08.14] Release checkpoints of VideoLLaMA2-72B-Base and VideoLLaMA2-72B.
- [2024.07.30] Release checkpoints of VideoLLaMA2-8x7B-Base and VideoLLaMA2-8x7B.
- [2024.06.25] 🔥🔥 As of Jun 25, our VideoLLaMA2-7B-16F is the Top-1 ~7B-sized VideoLLM on the MLVU Leaderboard.
- [2024.06.18] 🔥🔥 As of Jun 18, our VideoLLaMA2-7B-16F is the Top-1 ~7B-sized VideoLLM on the VideoMME Leaderboard.
- [2024.06.17] 👋👋 Update technical report with the latest results and the missing references. If you have works closely related to VideoLLaMA 2 but not mentioned in the paper, feel free to let us know.
- [2024.06.14] 🔥🔥 Online Demo is available.
- [2024.06.03] Release training, evaluation, and serving codes of VideoLLaMA 2.
🛠️ Requirements and Installation
Basic Dependencies:
- Python >= 3.8
- Pytorch >= 2.2.0
- CUDA Version >= 11.8
- transformers == 4.40.0 (for reproducing paper results)
- tokenizers == 0.19.1
[Online Mode] Install required packages (better for development):
git clone https://github.com/DAMO-NLP-SG/VideoLLaMA2 cd VideoLLaMA2 git checkout audio_visual pip install -r requirements.txt pip install flash-attn==2.5.8 --no-build-isolation pip install opencv-python==4.5.5.64 apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
[Offline Mode] Install VideoLLaMA2 as a Python package (better for direct use):
git clone https://github.com/DAMO-NLP-SG/VideoLLaMA2 cd VideoLLaMA2 git checkout audio_visual pip install --upgrade pip # enable PEP 660 support pip install -e . pip install flash-attn==2.5.8 --no-build-isolation pip install opencv-python==4.5.5.64 apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
🚀 Main Results
Multi-Choice Video QA & Video Captioning
Open-Ended Video QA
Audio QA
Audio-Visual QA
🌎 Model Zoo
Vision-only Checkpoints
Model Name | Model Type | Visual Encoder | Language Decoder | # Training Frames |
---|---|---|---|---|
VideoLLaMA2-7B-Base | Base | clip-vit-large-patch14-336 | Mistral-7B-Instruct-v0.2 | 8 |
VideoLLaMA2-7B | Chat | clip-vit-large-patch14-336 | Mistral-7B-Instruct-v0.2 | 8 |
VideoLLaMA2-7B-16F-Base | Base | clip-vit-large-patch14-336 | Mistral-7B-Instruct-v0.2 | 16 |
VideoLLaMA2-7B-16F | Chat | clip-vit-large-patch14-336 | Mistral-7B-Instruct-v0.2 | 16 |
VideoLLaMA2-8x7B-Base | Base | clip-vit-large-patch14-336 | Mixtral-8x7B-Instruct-v0.1 | 8 |
VideoLLaMA2-8x7B | Chat | clip-vit-large-patch14-336 | Mixtral-8x7B-Instruct-v0.1 | 8 |
VideoLLaMA2-72B-Base | Base | clip-vit-large-patch14-336 | Qwen2-72B-Instruct | 8 |
VideoLLaMA2-72B | Chat | clip-vit-large-patch14-336 | Qwen2-72B-Instruct | 8 |
VideoLLaMA2.1-7B-16F-Base | Base | siglip-so400m-patch14-384 | Qwen2-7B-Instruct | 16 |
VideoLLaMA2.1-7B-16F | Chat | siglip-so400m-patch14-384 | Qwen2-7B-Instruct | 16 |
Audio-Visual Checkpoints
Model Name | Type | Audio Encoder | Language Decoder |
---|---|---|---|
VideoLLaMA2.1-7B-AV | Chat | Fine-tuned BEATs_iter3+(AS2M)(cpt2) | VideoLLaMA2.1-7B-16F |
🤗 Demo
It is highly recommended to try our online demo first.
To run a video-based LLM (Large Language Model) web demonstration on your device, you will first need to ensure that you have the necessary model checkpoints prepared, followed by adhering to the steps outlined to successfully launch the demo.
Single-model Version
- Launch a gradio app directly (VideoLLaMA2.1-7B-AV is adopted by default):
python videollama2/serve/gradio_web_server_adhoc_av.py
🗝️ Training & Evaluation
Quick Start
To facilitate further development on top of our codebase, we provide a quick-start guide on how to train a customized VideoLLaMA2 with VideoLLaVA dataset and evaluate the trained model on the mainstream video-llm benchmarks.
- Training Data Structure: Follow the main branch(https://github.com/DAMO-NLP-SG/VideoLLaMA2/tree/main) of this VideoLLaMA2 codebase.
- Command:
VideoLLaMA2.1-audio pretraining
bash scripts/custom/pretrain_audio.sh
VideoLLaMA2.1-audio finetuning
bash scripts/custom/finetune_audio.sh
VideoLLaMA2.1-audio_visual finetuning
bash scripts/custom/va_joint.sh
- Evaluation Data Structure: Follow the main branch(https://github.com/DAMO-NLP-SG/VideoLLaMA2/tree/main) of this VideoLLaMA2 codebase.
- Command:
ClothoAQA.sh evaluation
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_audio_clothoAQA.sh
TUT2017 evaluation
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_audio_TUT2017.sh
VocalSound evaluation
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_audio_vocalsound.sh
AVQA_music evaluation
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_audio_video_AVQA.sh
AVSD evaluation (need to set azure openai key/endpoint/deployname)
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_audio_video_AVSD.sh
AVSSD evaluation (need to set azure openai key/endpoint/deployname)
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 bash scripts/eval/eval_audio_video_AVSSD.sh
Data Format
If you want to train a video-llm on your data, you need to follow the procedures below to prepare the audio/video/image sft data:
- Suppose your data structure is like:
VideoLLaMA2 ├── datasets │ ├── custom_sft │ | ├── audio │ | ├── video │ | ├── image | | └── custom.json
- Then you should re-organize the annotated audio/video/image sft data according to the following format:
[ { "id": 0, "audio": "audio/xxx.wav", "conversations": [ { "from": "human", "value": "\nPlease describe the sound event within the audio." }, { "from": "gpt", "value": "Loud television static dips in and out of focus." }, ... ], } { "id": 1, "video": "images/xxx.jpg", "conversations": [ { "from": "human", "value": "\nWhat are the colors of the bus in the image?" }, { "from": "gpt", "value": "The bus in the image is white and red." }, ... ], } { "id": 2, "video": "videos/xxx.mp4", "conversations": [ { "from": "human", "value": "
- Modify the
scripts/custom/finetune_audio.sh
:
... --data_path datasets/custom_sft/custom.json --data_folder datasets/custom_sft/ --pretrain_mm_mlp_adapter CONNECTOR_DOWNLOAD_PATH (e.g., DAMO-NLP-SG/VideoLLaMA2.1-7B-16F) ...
- Modify the
scripts/custom/va_joint.sh
:
... --data_path datasets/custom_sft/custom.json --data_folder datasets/custom_sft/ --pretrain_mm_mlp_adapter CONNECTOR_DOWNLOAD_PATH (e.g., DAMO-NLP-SG/VideoLLaMA2.1-7B-16F) ...
🤖 Inference
Audio/Video-Audio Inference:
import sys sys.path.append('./') from videollama2 import model_init, mm_infer from videollama2.utils import disable_torch_init import argparse
def inference(args):
model_path = args.model_path
model, processor, tokenizer = model_init(model_path)
if args.modal_type == "a":
model.model.vision_tower = None
elif args.modal_type == "v":
model.model.audio_tower = None
elif args.modal_type == "av":
pass
else:
raise NotImplementedError
# Audio-visual Inference
audio_video_path = "assets/00000368.mp4"
preprocess = processor['audio' if args.modal_type == "a" else "video"]
if args.modal_type == "a":
audio_video_tensor = preprocess(audio_video_path)
else:
audio_video_tensor = preprocess(audio_video_path, va=True if args.modal_type == "av" else False)
question = f"Who plays the instrument louder?"
# Audio Inference
audio_video_path = "assets/bird-twitter-car.wav"
preprocess = processor['audio' if args.modal_type == "a" else "video"]
if args.modal_type == "a":
audio_video_tensor = preprocess(audio_video_path)
else:
audio_video_tensor = preprocess(audio_video_path, va=True if args.modal_type == "av" else False)
question = f"Please describe the audio:"
# Video Inference
audio_video_path = "assets/output_v_1jgsRbGzCls.mp4"
preprocess = processor['audio' if args.modal_type == "a" else "video"]
if args.modal_type == "a":
audio_video_tensor = preprocess(audio_video_path)
else:
audio_video_tensor = preprocess(audio_video_path, va=True if args.modal_type == "av" else False)
question = f"What activity are the people practicing in the video?"
output = mm_infer(
audio_video_tensor,
question,
model=model,
tokenizer=tokenizer,
modal='audio' if args.modal_type == "a" else "video",
do_sample=False,
)
print(output)
if name == "main": parser = argparse.ArgumentParser()
parser.add_argument('--model-path', help='', required=True)
parser.add_argument('--modal-type', choices=["a", "v", "av"], help='', required=True)
args = parser.parse_args()
inference(args)
📑 Citation
If you find VideoLLaMA useful for your research and applications, please cite using this 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} }
👍 Acknowledgement
The codebase of VideoLLaMA 2 is adapted from LLaVA 1.5 and FastChat. We are also grateful for the following projects our VideoLLaMA 2 arise from:
- LLaMA 2, Mistral-7B, OpenAI CLIP, Honeybee.
- Video-ChatGPT, Video-LLaVA.
- WebVid, Panda-70M, LanguageBind, InternVid.
- VideoChat2, Valley, VTimeLLM, ShareGPT4V.
🔒 License
This project is released under the Apache 2.0 license as found in the LICENSE file. The service is a research preview intended for non-commercial use ONLY, subject to the model Licenses of LLaMA and Mistral, Terms of Use of the data generated by OpenAI, and Privacy Practices of ShareGPT. Please get in touch with us if you find any potential violations.