🚀 ビデオ多モーダル大規模言語モデルのSlow-Fastアーキテクチャ
このリポジトリには、論文 Slow-Fast Architecture for Video Multi-Modal Large Language Models で提示されたモデルが含まれています。
コード: https://github.com/SHI-Labs/Slow-Fast-Video-Multimodal-LLM
🚀 クイックスタート
このモデルは、ビデオ理解における時間的解像度と空間的詳細をバランスさせるために、新しいSlow-Fastアーキテクチャを使用しています。これにより、従来の大規模言語モデルのシーケンス長の制限を克服しています。また、「高速」トークンと「低速」トークンのデュアルトークン戦略を採用しています。「高速」トークンはビデオの概要を迅速に提供し、「低速」トークンはクロスアテンションを介して命令に応じた詳細な情報を抽出します。
💻 使用例
基本的な使用法
import torch
import os
import numpy as np
from decord import VideoReader, cpu
from llava.constants import IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN
from llava.conversation import conv_templates, SeparatorStyle
from llava.model.builder import load_pretrained_model
from llava.mm_utils import tokenizer_image_token, get_model_name_from_path
from llava.utils import disable_torch_init
def load_video(video_path, max_frames_num):
vr = VideoReader(video_path, num_threads=4)
fps = round(vr.get_avg_fps())
frame_idx = [i for i in range(0, len(vr), fps)]
uniform_sampled_frames = np.linspace(0, len(vr) - 1, max_frames_num, dtype=int)
frame_idx = uniform_sampled_frames.tolist()
spare_frames = vr.get_batch(frame_idx).asnumpy()
return spare_frames
model_path = "shi-labs/slowfast-video-mllm-qwen2-7b-convnext-576-frame64-s1t4"
video_path = "Slow-Fast-Video-Multimodal-LLM/assets/catinterrupt.mp4"
question = "Please describe this video in detail."
max_frames=64
disable_torch_init()
model_path = os.path.expanduser(model_path)
model_name = get_model_name_from_path(model_path)
tokenizer, model, image_processor, context_len = load_pretrained_model(model_path, None, model_name, use_flash_attn=True, trust_remote_code=True)
if model.config.mm_use_im_start_end:
prompt = DEFAULT_IM_START_TOKEN + DEFAULT_IMAGE_TOKEN + DEFAULT_IM_END_TOKEN + "
" + question
else:
prompt = DEFAULT_IMAGE_TOKEN + "
" + question
conv = conv_templates["qwen_1_5"].copy()
conv.append_message(conv.roles[0], prompt)
conv.append_message(conv.roles[1], None)
prompt = conv.get_prompt()
video = load_video(video_path, max_frames_num=max_frames)
video_tensor = image_processor.preprocess(video, return_tensors="pt")["pixel_values"].half().cuda()
videos = [video_tensor]
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors='pt')
input_ids = input_ids.to(device='cuda', non_blocking=True).unsqueeze(dim=0)
with torch.inference_mode():
output_ids = model.generate(
input_ids,
images=videos,
do_sample=True,
max_new_tokens=1024,
num_beams=1,
temperature=0.2,
top_p=1.0,
use_cache=True)
outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
print(f"User input: {question}
")
print(outputs)
📄 ライセンス
このプロジェクトはCC BY-NC 4.0ライセンスの下で提供されています。
📚 引用
@misc{wang2025slowfast,
title={Slow-Fast Architecture for Video Multi-Modal Large Language Models},
author={Haotian Wang and Zhengyuan Yang and Yue Zhao and Bin Lin and Zhe Chen and Yue Cao and Hongxia Yang},
year={2025},
eprint={2504.01328},\
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2504.01328v1},
}