🚀 Apollo:大型多模态模型中的视频理解探索
Apollo 是一系列大型多模态模型(LMMs),它推动了视频理解领域的技术发展。该模型支持以下任务:
- 长视频理解
- 时间推理
- 复杂视频问答
- 基于视频内容的多轮对话
Apollo 模型在处理长达数小时的视频方面表现出色,通过合理的设计决策,在速度和准确性之间取得了平衡。我们的模型仅用 30 亿参数就超越了大多数 70 亿参数的竞争对手,甚至可以与 300 亿规模的模型相媲美。
主要亮点:
- 可扩展性一致性:在较小模型和数据集上验证的设计决策能有效扩展到更大规模,降低了计算和实验成本。
- 高效视频采样:fps 采样和先进的令牌重采样策略(如 Perceiver)带来了更强的时间感知能力。
- 编码器协同效应:将 SigLIP - SO400M(图像)与 InternVideo2(视频)相结合,提供了强大的表征能力,在时间任务上优于单一编码器。
- ApolloBench:一个简化的评估基准(快 41 倍),专注于真正的视频理解能力。
🚀 快速开始
📦 安装指南
pip install -e .
pip install flash-attn --no-build-isolation
💻 使用示例
基础用法
import torch
from transformers import AutoModelForCausalLM
from apollo.mm_utils import (
KeywordsStoppingCriteria,
tokenizer_mm_token,
ApolloMMLoader
)
from apollo.conversations import conv_templates, SeparatorStyle
from huggingface_hub import snapshot_download
model_url = "Apollo-LMMs/Apollo-3B-t32"
model_path = snapshot_download(model_url, repo_type="model")
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(
model_path,
trust_remote_code=True,
low_cpu_mem_usage=True
).to(device=device, dtype=torch.bfloat16)
tokenizer = model.tokenizer
vision_processors = model.vision_tower.vision_processor
config = model.config
num_repeat_token = config.mm_connector_cfg['num_output_tokens']
mm_processor = ApolloMMLoader(
vision_processors,
config.clip_duration,
frames_per_clip=4,
clip_sampling_ratio=0.65,
model_max_length=config.model_max_length,
device=device,
num_repeat_token=num_repeat_token
)
video_path = "path/to/video.mp4"
question = "Describe this video in detail"
mm_data, replace_string = mm_processor.load_video(video_path)
conv = conv_templates["qwen_2"].copy()
conv.append_message(conv.roles[0], replace_string + "\n\n" + question)
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()
input_ids = tokenizer_mm_token(prompt, tokenizer, return_tensors="pt").unsqueeze(0).to(device)
stop_str = conv.sep if conv.sep_style != SeparatorStyle.TWO else conv.sep2
stopping_criteria = KeywordsStoppingCriteria([stop_str], tokenizer, input_ids)
with torch.inference_mode():
output_ids = model.generate(
input_ids,
vision_input=[mm_data],
data_types=['video'],
do_sample=True,
temperature=0.4,
max_new_tokens=256,
top_p=0.7,
use_cache=True,
num_beams=1,
stopping_criteria=[stopping_criteria]
)
pred = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
print(pred)
📚 详细文档
如果您觉得这个项目有用,请考虑引用以下文献:
@article{zohar2024apollo,
title={Apollo: An Exploration of Video Understanding in Large Multimodal Models},
author={Zohar, Orr and Wang, Xiaohan and Dubois, Yann and Mehta, Nikhil and Xiao, Tong and Hansen-Estruch, Philippe and Yu, Licheng and Wang, Xiaofang and Juefei-Xu, Felix and Zhang, Ning and Yeung-Levy, Serena and Xia, Xide},
journal={arXiv preprint arXiv:2412.10360},
year={2024}
}
更多详细信息,请访问项目网站或查看论文。
📄 许可证
本项目采用 Apache - 2.0 许可证。
属性 |
详情 |
模型类型 |
大型多模态模型(LMMs) |
训练数据 |
ApolloBench、Video - MME、MLVU、LongVideoBench、NExTQA、PerceptionTest |