🚀 LongVA-7B-TPO
このリポジトリには、論文 Temporal Preference Optimization for Long-form Video Understanding で説明されているモデルが含まれています。
論文 Temporal Preference Optimization for Long-form Video Understanding で紹介された LongVA-7B-TPO は、LongVA-7B をベースに時間的な嗜好に基づいて最適化されています。LongVA-7B-TPO モデルは、さまざまなベンチマークで最先端の性能を発揮し、LongVA-7B と比較して平均 2% の性能向上を示しています。



✨ 主な機能
LongVA-7B-TPO は、長時間のビデオ理解のために時間的な嗜好最適化を行ったモデルです。LongVA-7B をベースに最適化されており、複数のベンチマークで高い性能を発揮します。
📦 インストール
インストールに関する具体的な手順は、github リポジトリ を参照してください。
💻 使用例
基本的な使用法
以下のコードを使用して、モデルを使用することができます。詳細な情報については、github リポジトリ を参照してください。
from longva.model.builder import load_pretrained_model
from longva.mm_utils import tokenizer_image_token, process_images
from longva.constants import IMAGE_TOKEN_INDEX
from PIL import Image
from decord import VideoReader, cpu
import torch
import numpy as np
torch.manual_seed(0)
model_path = "ruili0/LongVA-TPO"
image_path = "local_demo/assets/lmms-eval.png"
video_path = "local_demo/assets/dc_demo.mp4"
max_frames_num = 16
gen_kwargs = {"do_sample": True, "temperature": 0.5, "top_p": None, "num_beams": 1, "use_cache": True, "max_new_tokens": 1024}
tokenizer, model, image_processor, _ = load_pretrained_model(model_path, None, "llava_qwen", device_map="cuda:0")
prompt = "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<image>\nDescribe the image in details.<|im_end|>\n<|im_start|>assistant\n"
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
image = Image.open(image_path).convert("RGB")
images_tensor = process_images([image], image_processor, model.config).to(model.device, dtype=torch.float16)
with torch.inference_mode():
output_ids = model.generate(input_ids, images=images_tensor, image_sizes=[image.size], modalities=["image"], **gen_kwargs)
outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
print(outputs)
print("-"*50)
prompt = "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n<image>\nGive a detailed caption of the video as if I am blind.<|im_end|>\n<|im_start|>assistant\n"
input_ids = tokenizer_image_token(prompt, tokenizer, IMAGE_TOKEN_INDEX, return_tensors="pt").unsqueeze(0).to(model.device)
vr = VideoReader(video_path, ctx=cpu(0))
total_frame_num = len(vr)
uniform_sampled_frames = np.linspace(0, total_frame_num - 1, max_frames_num, dtype=int)
frame_idx = uniform_sampled_frames.tolist()
frames = vr.get_batch(frame_idx).asnumpy()
video_tensor = image_processor.preprocess(frames, return_tensors="pt")["pixel_values"].to(model.device, dtype=torch.float16)
with torch.inference_mode():
output_ids = model.generate(input_ids, images=[video_tensor], modalities=["video"], **gen_kwargs)
outputs = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0].strip()
print(outputs)
📚 ドキュメント
評価結果
モデル |
サイズ |
LongVideoBench |
MLVU |
VideoMME (Short) |
VideoMME (Medium) |
VideoMME (Long) |
VideoMME (Average) |
LongVA-7B [1] |
7B |
51.3 |
58.8 |
61.3/61.6 |
50.4/53.6 |
46.2/47.6 |
52.6/54.3 |
LongVA-TPO (ours) |
7B |
54.2 |
61.7 |
63.1/66.6 |
54.8/55.3 |
47.4/47.9 |
55.1/56.6 |
📄 ライセンス
このプロジェクトでは、特定のデータセットとチェックポイントを使用しており、それぞれの元のライセンスに従う必要があります。ユーザーは、これらの元のライセンスのすべての条件に準拠する必要があり、これにはデータセットの OpenAI 利用規約やベース言語モデルの特定のライセンス (Qwen2 ライセンス) が含まれます。このプロジェクトは、元のライセンスに定められた制約以外に追加の制約を課すものではありません。さらに、ユーザーはデータセットとチェックポイントの使用がすべての適用される法律と規制に準拠していることを確認するように注意する必要があります。
引用
BibTeX
@article{li2025temporal,
title={Temporal Preference Optimization for Long-Form Video Understanding},
author={Li, Rui and Wang, Xiaohan and Zhang, Yuhui and Wang, Zeyu and Yeung-Levy, Serena},
journal={arXiv preprint arXiv:2501.13919},
year={2025}
}
参考文献
[1]. Zhang, P., Zhang, K., Li, B., Zeng, G., Yang, J., Zhang, Y., ... & Liu, Z. (2024). Long context transfer from language to vision. arXiv preprint arXiv:2406.16852.